CDO.Message Classic ASP - Adding attachment - asp-classic

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.

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.

Related

The transport failed to connect to the server in Classic ASP

I want to send a message but I am getting this error. Does anyone have any idea why I am getting this error?
On Error Resume Next
mTo = "*****"
mBody = "<strong>New Signup</strong><br><br> " & _
"Time: " & now() & "<br><br> "
If (mTo <> "") Then
Set objMail = Server.CreateObject("CDO.Message")
With objMail
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 ' SendUsingPort
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.*****.ca" ' Name or IP of remote SMTP server
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 ' Server port
.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpConnectionTimeout") = 60
.Configuration.Fields.Update
.From = "Home Style - New Signup <info#******.ca>"
.To = mTo
.Subject = "Home Style - New Signup"
.HTMLBody = mBody
.Send
End with
set objMail = nothing
End If
If Err.Number <> 0 Then
Response.Write (Err.Description)
Response.End
Please let me know where I am missing some code.
looks like you're trying to use authentication, but you're not sending over login details.
see https://stackoverflow.com/a/6500470/5544752 for more info

Cannot send email from godaddy smtp using classic asp - going mad

I am really struggling with something which is pretty basic and need some help as it was not forthcoming from godaddy support!
For some reason the code below is not sending out any emails.
Code seems to be executed property and riddled it with lots of debug msgs but to no helping!
Te "From" email address is valid and has no issues! Any ideas? Port?
cheers, Jay
<%
Dim objNewMail
Set objNewMail = Server.CreateObject("CDO.Message")
objNewMail.From = "info#example.com"
objNewMail.To = "info#example.com"
objNewMail.Subject = "Interesting property sent by xxx"
objNewMail.TextBody = "Click the following link to see the property :" '& vbcr & vbcr & "http://www.maltawide.eu/default.asp?pid="
' GoDaddy SMTP Settings
'I had to remove the smpt settings as I dont have enough rep to post two links!
Response.Write ("Message sent successfully!")
%>
I'm not sure why your message failed, but here is code from a working mail form hosted at GoDaddy. All you need to do is build the form page to submit the form fields used in the script, or change the form field names in the script to match your existing form, or replace the forms with strings. Examples of both form entry and assigned variable values are included in the example's ' Create the message part of the code.
<%
Dim strBody
Dim strToAddress
Dim strFromAddress
Dim strReplyAddress
Dim strBlindCC
' Create the message
strBody = Request.Form("Message")
strToAddress = Request.Form("ToAddress")
strFromAddress = Request.Form("FromAddress")
strReplyAddress = "NoReply#WebSite.com"
strBlindCC = "BlindCC#WebSite.com"
' Include the schemas
sendUrl="http://schemas.microsoft.com/cdo/configuration/sendusing"
smtpUrl="http://schemas.microsoft.com/cdo/configuration/smtpserver"
' Set the mail server configuration
Set objConfig=CreateObject("CDO.Configuration")
objConfig.Fields.Item(sendUrl)=2 ' cdoSendUsingPort
objConfig.Fields.Item(smtpUrl)="relay-hosting.secureserver.net"
objConfig.Fields.Update
' Send the message
Set objMail=CreateObject("CDO.Message")
Set objMail.Configuration=objConfig
objMail.From=strFromAddress
objMail.ReplyTo=strReplyAddress
objMail.To=strToAddress
objMail.BCC=strBlindCC
objMail.Subject=strSubject
objMail.HTMLBody = strBody
objMail.Send
%>

Getting error when sending data through form (Office365)

I am trying to debug this issue when sending this information from a form, but I keep getting this error.
error '8004020e'
/contacthandler.asp, line 45
I have not done much work in asp, but I've managed to clean this file up a little bit from the previous developer (still had the error). The error happens at the .Send..forgot to clarify that.
Here is the code. Any help is appreciated.
'declare variables
dim name, phone, email, comment, service, returnPage
'set variables to the corresponding fields from contact form
name = request.form("custName")
phone = request.form("custPhone")
email = request.form("custEmail")
comment = request.form("custNotes")
service = request.form("service")
returnPage = request.form("page")
dim theEmail
' set the email content data
theEmail = "<h3>Contact from website, information below.</h3><table border='0'><tr><th>Customer Name:<td>"&name
theEmail = theEmail&"<tr><th>Phone Number:<td>"&phone&"<tr><th>Email Address:<td>"&email&"<tr><th>Service Category:<td>"&service
theEmail = theEmail&"<tr><th valign='top'>Comments/Notes:<td>"&comment&"</table>"
' send the email
dim sch
sch = "http://schemas.microsoft.com/cdo/configuration/"
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(sch & "sendusing") = 2 ' cdoSendUsingPort
.Item(sch & "smtpserverport") = 587
.Item(sch & "smtpserver") = "smtp.office365.com"
.Item(sch & "smtpauthenticate") = 1
.Item(sch & "sendusername") = "########"
.Item(sch & "sendpassword") = "########"
.update
End With
Set cdoMessage = CreateObject("CDO.Message")
With cdoMessage
Set .Configuration = cdoConfig
.From = name & "<" & email & ">"
.To = "info#mywebsite.com"
.Subject = "Website - "&service&" Request"
.HTMLBody = theEmail
.Send
End With
Set cdoMessage = Nothing
Set cdoConfig = Nothing
'response.write "sent, check the mail"
response.redirect "thankyou.asp"
'returnPage&".asp"
MSDN (http://msdn.microsoft.com/en-us/library/ms527318%28v=exchg.10%29.aspx) suggests you need to format your .From field as follows:
.From """" & name & """ <" & email & ">"
I used Google to look up the error code and I found lots of sites they meant there is an issue with sending the data. That can be another source of trouble.
What will happen if you replace
.Item(sch & "sendusing") = 2 ' cdoSendUsingPort
by
.Item(cdoSendUsingMethod) = 1 'cdoSendUsingPickup
Additional try it without any comments.

How to I edit cdosys.asp in "classic ASP" to send e-mail?

I have a site that is all static content except the "Contact" page. My hosting service has me on an IIS server, so they gave me generic cdosys.asp file. As you know if you've used a cdosys.asp, you point the form submit from the contact page at it, and the cdosys.asp shoots whatever the site visitor put in the form fields in an email to me, then relays the visitor to a "Thanks for writing" page.
Here's my glitch. The only server-side language I've learned is ColdFusion. No ASP. The cdosys file was simple enough to figure out that I changed a few text strings so it points to my mail server and then the thank-you page. But, my contact input form only requires one out of the three offered fields. Two are optional. But the cdosys is choking on that. It thinks all the fields are required. It only works if all three have content. I Googled all over trying to find an old ASP tutorial. Can some kindly ASP pro out there tell me how to edit the code below to allow two of my three form fields to have no content and still send me an email?
<%
For Field = 1 to Request.Form.Count - 3
FieldName = Replace(Request.Form.Key(Field),"_"," ")
FieldValue = Request.Form.Item(Field)
Body = Body & FieldName & ": " & FieldValue & VbCrLf
Next
'Dimension variables
Dim objCDOSYSCon
'Create the e-mail server object
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")
'Set and update fields properties
With objCDOSYSCon
'Outgoing SMTP server
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.domain.com" 'was "SMTPSERVER"
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 'CDO Port
.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Timeout
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
.Fields.Update
End With
'Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon
'Set and update email properties
With objCDOSYSMail
'0=Low, 1=Normal, 2=High
.Fields("urn:schemas:httpmail:importance").Value = 1
'Who the e-mail is from
.From = Request.Form("email_address")
'Who the e-mail is sent to
.To = "myname#domain.com"
'Who the e-mail is CC'd to
.Cc = ""
'The subject of the e-mail
.Subject = Request.Form("email_subject")
'Set the e-mail body format (HTMLBody=HTML TextBody=Plain)
.TextBody = Body
.Fields.Update
'Send the e-mail
.Send
End With
'Close the server mail object
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
'Rederect after sending email
Response.Redirect Request.Form("redirect_to")
%>
Try like this:
For Field = 1 to Request.Form.Count - 3
FieldName = Replace(Request.Form.Key(Field),"_"," ")
FieldValue = Request.Form.Item(Field)
if isnull(fieldvalue) then fieldvalue = "(null)"
Body = Body & FieldName & ": " & FieldValue & VbCrLf
Next

How to add CDO reference in an asp web page

I'm trying to create a new email in asp and send it to a mail server using CDO. I believe I need a reference for CDO or Send Email functionality. In the book it says use this:
Set objNewMail = Server.CreateObject("CDONTS.NewMail")
Unfortunately that is now working as it errors out in asp. Now sure how to add the reference, or com object so that it will work through iis using asp. The book I'm referring to is: ASP In a nut shell 2nd addition. "The CDO Object Model" I'm using windows xp or windows server 2003.
use this instead of cdonts
<!--
METADATA
TYPE="typelib"
UUID="CD000000-8B95-11D1-82DB-00C04FB1625D"
NAME="CDO for Windows 2000 Library"
-->
<%
Function SendMail(sFrom, ToA, Subject, Mybody)
Dim iMsg,iConf
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Dim Flds
Set Flds = iConf.Fields
With Flds
' assume constants are defined within script file
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = MAILSERVER
.Item(cdoSMTPConnectionTimeout) = 60
.Item(cdoURLGetLatestVersion) = True
.Update
End With
With iMsg
Set .Configuration = iConf
.To = ToA
.From = sFrom
.Subject = Subject
.TextBody = Mybody
.Send
End With
Set iConf = nothing
Set iMsg = nothing
If Err.Number = 0 Then
SendMail = True
Else
SendMail = Err.Number&":"&Err.Description
End If
On Error Goto 0
set objSendMail = Nothing
End Function
%>

Resources