Knowledgebase: Windows Hosting
How to send email using CDO via ASP ?
Posted by Tarak D on 25 January 2012 08:54 PM
<%
Dim mymail
'Create an instance of the CDOSYS Object
set mymail = createobject("CDO.Message")
mymail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
mymail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="mail.YourDomain.com" 'this should be changed to the smtp server you have access to
mymail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25 'or the port configured for smtp
'you can uncomment the lines below if your mail server requires authentication
mymail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=1
mymail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername")="youremail@yourdomain.com" ' this should be the authenticated user who can send emails
mymail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")="email_password" ' the password of the authenticated user
 
'update the configuration options
mymail.Configuration.Fields.Update
 
' the email address to send to
mymail.to = "to_email@domain.com"
'if you want to include a name then
'mymail.to = "Firstname Surname <email_address@otherdomain.com>"
 
'the email address to send from
mymail.from = "from_email@yourdomain.com"
'if you want to include a name then
'mymail.from = "Firstname Surname <your_email@domain.com>"
 
'the cc email address to send to
'mymail.cc = "cc_email@ccdomain.com"
 
'the bcc email address to send to
'mymail.bcc = "bcc_email@bccdomain.com"
 
'enter the subject of the email
mymail.subject = "Email Subject"
 
'to send an html email
mymail.HTMLbody = "<b>This is the HTML email body</b>"
'to send a plain text email
mymail.Textbody = "This is the plain text email body"
 
'add an attachment
'mymail.AddAttachment server.mappath("/path_to_attachment/file.ext")
 
'send the email
mymail.send
 
'clean the objects
set mymail=nothing
%>
(217 vote(s))
Helpful
Not helpful