CDOSYS email object reference - ASP Scripts


The following example shows you how to use the CDOSYS email object.
Optional properties can be added to specify more information about the message.

Don't forget to attach your server configuration to each CDOSYS message or the server will return an unfriendly CDO.Message.1 error message.

<%

' Define email object and configuration
Dim objMail, objConfig 

' Create a new email instance
Set objMail = Server.CreateObject("CDO.Message") 

' ==================================== 
' Create a new configuration object
Set objConfig = Server.cr&#101;ateObject("CDO.Configuration") 

' Set configurations
With objConfig 

' SMTP Server (be sure to change this configuration!)
.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.example.com" 

' SMTP Port
.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 

' Update configurations
.Fields.Update
End With 

' Apply configurations
Set objMail.Configuration = objConfig 

' ==================================== 

' Set email properties

' Sender email
objMail.From = "sender@domain.com"

' To recipients
objMail.To = "foo@domain.com" 

' CC and CCN recipients
objMail.Cc = "bar@domain.com; baz@domain.com" 
objMail.Bcc = "boo@domain.com; bof@domain.com" 

' Email subject
objMail.Subject = "Mail subject" 

' Priority level
objMail.Fields("urn:schemas:httpmail:importance").Value = 2 
objMail.Fields.Update() 

' Attach a file
objMail.AddAttachment("d:\inetpub\webs\path\to\file.zip") 

' Email message
objMail.TextBody = "This is text" ' Email format 
objMail.HTMLBody = "This is HTML" ' HTMl format

' Send email
objMail.Send() 

' Release object
Set objMail = Nothing 

%> 

ASP.weppos.com and ASP.weppos.it are property of Simone Carletti.
Discover my website or visit my Simone Carletti's profile on LinkedIn