Question

I am having problems trying to add an attachment to an email using Classic ASP. I have trawled forums and it seems I needed to add .AddAttachment = "c:\users\samplb\logoblack.gif" but the form doesn't work anymore. It comes up with the "The website cannot display the page" message.

Here is my Code:

<% 

name = request.form("name")
Message = request.form("Message")


Set cdoConfig = CreateObject("CDO.Configuration")  

With cdoConfig.Fields  
    .Item(cdoSendUsingMethod) = cdoSendUsingPort  
    .Item(cdoSMTPServer) = "xxx"  
    .Update  
End With 

Set cdoMessage = CreateObject("CDO.Message")  

With cdoMessage 
    Set .Configuration = cdoConfig 
    .From = "test@me.co.uk"
    .To = "test@me.co.uk" 
    .Subject = "Feedback / Suggestions" 
    .AddAttachment = "c:\users\samplb\logoblack.gif" 
    .TextBody = "Name: " & name & vbcrlf & vbcrlf & "Message: " & Message  
    .Send 
End With 

Set cdoMessage = Nothing  
Set cdoConfig = Nothing  
%>

Does anyone know why it might not be working? When I take the .AddAttachment out the form works fine but I really need it to send the attachment.

Was it helpful?

Solution

The problem is .AddAttachment() is a method not a property try changing your code like this;

Call .AddAttachment("c:\users\samplb\logoblack.gif")

or to return the attachment as a CDO.BodyPart use;

Set cdoBodyPart = .AddAttachment("c:\users\samplb\logoblack.gif")

Note: See the AddAttachment Method (MSDN Library) for more information about the method and how to use it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top