Sending mail using Classic ASP. Print

  • 12

 

To send mail using Classic ASP script you will need to use the built-in email function called CDONTS or CDOSYS. CDOSYS is the recommended way to send email since Windows 2003 or 2008 no longer supports CDONTS. Microsoft suggests all users convert to CDOSYS. EPhost does not currently support any additional components to send email.

The example below outlines the conversion to CDOSYS and is also a very good example of of the core code to send email. The reader should be familiar with ASP and the necessary use of setting variables to post information to this script.

Conversion from CDONTS to CDOSYS (Microsoft does not support CDONTS)

Switching from CDONTS to CDOSYS couldn't be easier. The following is an example of an ASP script used to send email with CDONTS. Note, that this code is using variables called strTo, strFrom, strSubject and strBody that have either been set previously or posted to this page using a form.

 

<%
Set oMail = CreateObject("CDONTS.NewMail")
oMail.BodyFormat = 0
oMail.MailFormat = 0
oMail.Importance = 2
oMail.AttachFile FbkFile
oMail.to = strTo
oMail.From = strFrom
oMail.Subject = strSubject
oMail.Body = strBody
oMail.Send
Set oMail = Nothing
%>

 

Using CDOSYS we can accomplish the same thing. There is more to CDOSYS than this, but the example shown below should be enough to generate simple email messages. If you need to include HTML tags in your email message, you must use cdoMessage.HTMLBody instead of cdoMessage.TextBody. Note, this script has simple string text directly in code. It is likely you would replace the text with a string variable. See above example.

 

<%
Set myMail=CreateObject("CDO.Message")
    myMail.Subject="This is an email"
    myMail.From="YOUR@EMAIL.COM"
    myMail.To="THEIR@EMAIL.COM"
    myMail.TextBody="Hello world!"
    myMail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
    'SMTP server
    myMail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserver")="mail.ephost.com"
    'SMTP port
    myMail.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=465
    myMail.Configuration.Fields.Update
    myMail.Send
    set myMail=nothing
%>

 


Was this answer helpful?

« Back