CDO.Message Classic ASP - Adding attachment

Samp picture Samp · Apr 1, 2014 · Viewed 11.1k times · Source

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 = "[email protected]"
    .To = "[email protected]" 
    .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.

Answer

user692942 picture user692942 · Apr 1, 2014

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.