View Full Version : CDO email not working

10-26-2007, 04:43 PM

I am trying to collect information from an online form and to then send a copy of this information by email to the person who input it and to the Webmaster.

This is what I have at the moment:

Dim sFullNameTitle,sFullName,sEmailTitle,sEmailAddress,sBusinessTitle,sBusinessName,sCountryTitle,sCount ryName,MessageName,MessageTitle
sFullNameTitle = "Fullname"
sFullName = Request.Form("Fullname")
sEmailTitle = "Email"
sEmailAddress = Request.Form("Email")
sBusinessTitle = "Business"
sBusinessName = Request.Form("Business")
sCountryTitle = "Country"
sCountryName = Request.Form("Country")
MessageName = "Message"
MessageTitle = Request.Form("Message")

Set myMail=CreateObject("CDO.Message")

myMail.Subject="Your Submission"

myMail.TextBody="Message" & vbcrlf & vbcrlf & _

"Your copy. Please do not reply to this email" & vbcrlf & _

"Full name: " & vbcrlf & _
"Email: " & vbcrlf & _
"Business: " & vbcrlf & _
"Country: " & vbcrlf & _
"Message: " & vbcrlf & _

set myMail=nothing


I am not getting any error messages, but neither does anyone receive any email messages.

Maybe I should be using myMail.HTMLBody = "<HTML Code here>" instead of:

myMail.TextBody="Message" & vbcrlf & vbcrlf & _

Yet, this does not explain why the data input in the form fields (or the email addresses) are not being picked up.

Any suggestions, please?



10-26-2007, 05:21 PM
Where's your mail server?

If you don't have an SMTP server running on localhost that it can use as default*, then you're going to have to specify a mail server to use, and a method for passing emails to it.

For example:

Set oMail =Server.CreateObject("CDO.Message")
oMail.HTMLBody = sMailBody
oMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 ' send using SMTP port. 1 = send using local pickup directory.
oMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.mydomain.com"
oMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") =25
set oMail=nothing

*I'm not actually sure about this. My understanding was that you should ALWAYS specify a mailserver with CDO. That's the way I've always done it, anyhow.

Either way, see this guide to sending mail with CDO (http://www.powerasp.net/content/new/sending_email_cdosys.asp). As you can see, depending on how your mail server is set up regarding authentication etc, there's actually quite a few fields you need to set in addition to the usual To, From, Subject etc.