Sending email using ASP (CDOSYS)

To send email via ASP script, please refer to following sample code.

Note: Our mail servers require your script to pass SMTP authentication in order to send email through the script.

Sample Code:

Dim ObjSendMail
Set ObjSendMail = CreateObject("CDO.Message")

'This section provides the configuration information for the remote SMTP server.
Dim strSMTPServer, strSender, strSenderPassword, strRecipient, strSubject, strBody
strSMTPServer = "mail.yourdomain.com"
strSender = "[email protected]"
strSenderPassword = "password"
strRecipient = "[email protected]"
strSubject = "CDOSYS Email"
strBody = "This is a test. Please contact Microsoft if you have any problems in using it."

ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Send the message using the network (SMTP over the network).
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPServer
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 2525
'SMTP Port
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
'Use SSL for the connection (True or False)
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

' If your server requires outgoing authentication uncomment the lines bleow and use a valid email address and password.
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
'basic (clear-text) authentication
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = strSender
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = strSenderPassword

ObjSendMail.Configuration.Fields.Update
'End remote SMTP server configuration section

ObjSendMail.From = strSender
ObjSendMail.To = strRecipient
ObjSendMail.Subject = strSubject

'Switch the comments around to send html/text email
ObjSendMail.HTMLBody = strBody
'ObjSendMail.TextBody = ""

ObjSendMail.Send
Set ObjSendMail = Nothing
Response.Write "Email has been sent."

 

  • 4 Users Found This Useful
Was this answer helpful?