CDO message attach files

CDO message attach files

am 18.06.2007 14:45:26 von sallysmedly

Hi,

I have a page where a user can browse for and attach 2 files to an
email.

The email works fine when I try to send a selected file from the
server, but I have added in some script so that it sends the files the
user has selected, but this part won't work.

Any suggestions would be much appreciated.

emailtest.asp

<%
Dim objMail
Set objMail = Server.CreateObject("CDO.Message")
Set objConfig = Server.CreateObject("CDO.Configuration")

'Configuration:
objConfig.Fields(cdoSendUsingMethod) = cdoSendUsingPort

objConfig.Fields(cdoSMTPServer)="auth.smtp.mydomain.co.uk"
objConfig.Fields(cdoSMTPServerPort)=25
objConfig.Fields(cdoSMTPAuthenticate)=cdoBasic
objConfig.Fields(cdoSendUserName) = "username"
objConfig.Fields(cdoSendPassword) = "password"

'Update configuration
objConfig.Fields.Update
Set objMail.Configuration = objConfig

objMail.From ="xxx@mydomain.com"
objMail.To = "xxx@mydomain.com"
objMail.Subject = "You have a new message"
objMail.TextBody = "You have a entry from "


'this bit doesn't work
for each file in Upload.Files
fn=File.ExtractFilename
objMail.AddAttachment Server.MapPath(fn),fn
next
'end of bit not working

'this does work, but only attaches a fixed file, rather than user
selected file
'objMail.AddAttachment "http://www.mydomian.com/code.htm"
objMail.Send

If Err.Number = 0 Then
Response.Write("Mail sent!")
Else
Response.Write("Error sending mail. Code: " & Err.Number)
Err.Clear
End If
Set objMail=Nothing
Set objConfig=Nothing
%>


form email:




Untitled Document
















Re: CDO message attach files

am 29.06.2007 01:05:09 von David Morgan

http://www.4guysfromrolla.com/webtech/112298-1.shtml

Is the uploaded file in the same folder as the ASP page? It is unlikely
that Server.MapPath should be used with ExtractFilename.

Just attached based on the full folder name and file name of the uploaded
file.



wrote in message
news:1182170726.284217.287810@p77g2000hsh.googlegroups.com.. .
> Hi,
>
> I have a page where a user can browse for and attach 2 files to an
> email.
>
> The email works fine when I try to send a selected file from the
> server, but I have added in some script so that it sends the files the
> user has selected, but this part won't work.
>
> Any suggestions would be much appreciated.
>
> emailtest.asp
>
> <%
> Dim objMail
> Set objMail = Server.CreateObject("CDO.Message")
> Set objConfig = Server.CreateObject("CDO.Configuration")
>
> 'Configuration:
> objConfig.Fields(cdoSendUsingMethod) = cdoSendUsingPort
>
> objConfig.Fields(cdoSMTPServer)="auth.smtp.mydomain.co.uk"
> objConfig.Fields(cdoSMTPServerPort)=25
> objConfig.Fields(cdoSMTPAuthenticate)=cdoBasic
> objConfig.Fields(cdoSendUserName) = "username"
> objConfig.Fields(cdoSendPassword) = "password"
>
> 'Update configuration
> objConfig.Fields.Update
> Set objMail.Configuration = objConfig
>
> objMail.From ="xxx@mydomain.com"
> objMail.To = "xxx@mydomain.com"
> objMail.Subject = "You have a new message"
> objMail.TextBody = "You have a entry from "
>
>
> 'this bit doesn't work
> for each file in Upload.Files
> fn=File.ExtractFilename
> objMail.AddAttachment Server.MapPath(fn),fn
> next
> 'end of bit not working
>
> 'this does work, but only attaches a fixed file, rather than user
> selected file
> 'objMail.AddAttachment "http://www.mydomian.com/code.htm"
> objMail.Send
>
> If Err.Number = 0 Then
> Response.Write("Mail sent!")
> Else
> Response.Write("Error sending mail. Code: " & Err.Number)
> Err.Clear
> End If
> Set objMail=Nothing
> Set objConfig=Nothing
> %>
>
>
> form email:
>
>
>
>
> Untitled Document
>
>
>
>
>


>


>
>


>


>
>


>


>
>


>

>
>
>