Summary

This article describes how to send an email using classic ASP and the Microsoft CDOSYS component.

Send e-mail with “friendly name” and “Reply To”

<%
Set oMail=CreateObject("CDO.Message")
oMail.Subject="Example Sending a text email with an friendly name and reply-to"
oMail.From="John Smith <email@example.com>"
oMail.ReplyTo = "email@example.com"
oMail.To="email@example.com"
oMail.TextBody="Hello World!"
oMail.BodyPart.charset = "UTF-8"
oMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
oMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="localhost"
'Server port
oMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
oMail.Configuration.Fields.Update
oMail.Send
set oMail=nothing
%>

Send text e-mail

<%
Set oMail=CreateObject("CDO.Message")
oMail.Subject="Example Sending a text email"
oMail.From="email@example.com"
oMail.To="email@example.com"
oMail.TextBody="Hello World!"
oMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
oMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="localhost"
'Server port
oMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
oMail.Configuration.Fields.Update
oMail.Send
set oMail=nothing
%>

Sending text e-mail with Bcc and CC fields

<%
Set oMail=CreateObject("CDO.Message")
oMail.Subject="Example Sending a text email with Bcc and CC fields"
oMail.From="email@example.com"
oMail.To="email@example.com"
oMail.Bcc="email@example.com"
oMail.Cc="email@example.com"
oMail.TextBody="Hello World!"
oMail.BodyPart.charset = "UTF-8"
oMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
oMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="localhost"
'Server port
oMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
oMail.Configuration.Fields.Update
oMail.Send
set oMail=nothing
%>

Send HTML e-mail

<%
Set oMail=CreateObject("CDO.Message")
oMail.Subject="Example Sending an HTML email"
oMail.From="email@example.com"
oMail.To="email@example.com"
oMail.BodyPart.charset = "UTF-8"
oMail.HTMLBody = "<h1>Hello World!</h1>"
oMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
oMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="localhost"
'Server port
oMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
oMail.Configuration.Fields.Update
oMail.Send
set oMail=nothing
%>

Sending e-mail with webpage as it’s content

<%
Set oMail=CreateObject("CDO.Message")
oMail.Subject="&amp;amp;gt;Example Sending an HTML email that sends a webpage from a website"
oMail.From="email@example.com"
oMail.To="email@example.com"
oMail.BodyPart.charset = "UTF-8"
oMail.CreateMHTMLBody "http://www.example.co.uk/"
oMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
oMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="localhost"
'Server port
oMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
oMail.Configuration.Fields.Update
oMail.Send
set oMail=nothing
%>

Send text e-mail with attachment

<%
Set oMail=CreateObject("CDO.Message")
oMail.Subject="Example Sending a text email with an Attachment"
oMail.From="email@example.com"
oMail.To="email@example.com"
oMail.TextBody="Hello World!"
oMail.BodyPart.charset = "UTF-8"
oMail.AddAttachment "c:/inetpub/vhosts/example.com/httpdocs/index.htm"
oMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
oMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="localhost"
'Server port
oMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
oMail.Configuration.Fields.Update
oMail.Send
set oMail=nothing
%>

Send e-mail using a remote server and SMTP authentication

<%
Set oMail=CreateObject("CDO.Message")
oMail.Subject="Example Sending a text email with an Attachment"
oMail.From="email@example.com"
oMail.To="email@example.com"
oMail.TextBody="Hello World!"
oMail.BodyPart.charset = "UTF-8"
oMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
oMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.example.com"
'Server port
oMail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
'Enable Basic SMTP authentication. (clear-text)
oMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
'Valid email addresss / username (replace demo@example.com with your own)
oMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="demo@example.com"
'Passworde (replace 'password' with your own)
oMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="password"
oMail.Configuration.Fields.Update
oMail.Send
set oMail=nothing
%>