Send an Email Using ASP (CDOSYS)
Please use the “Print” function at the bottom of the page to create a PDF.
For Windows Web Hosting packages
In this article, we'll provide an example that you can adapt with your own details to send an email using ASP.
CDOSYS, which replaced CDONTS in 2000, provides you with Collaboration Data Objects in order to send authenticated emails (requiring a username and password) in ASP.
Guided Steps
- Copy the text from the box below and paste it into a text editor, such as NotePad.
- Edit the details shown below in this color.
- Save the file with the extension .asp (Ex: sendmail.asp).
- Upload the file to your webspace.
- Access the file through your browser to verify that it works (Ex: https://www.example.com/sendmail.asp).
<%
CONST SMTPSendUsing = 2 ' Send using Port (SMTP over the network)
CONST SMTPServer = "smtp.ionos.com"
CONST SMTPServerPort = 465
CONST SMTPConnectionTimeout = 10 'seconds
CONST SMTPUser = "sender@example.com
"
CONST SMTPPassword = "EnterEmailPasswordHere"
dim sSubject, sEmail, sMailBody, sFrom, sReadReceipt, sMsg
sSubject = "Test"
sEmail = "recipient@example.com"
sMailBody = "This is a test message."
sFrom = "sender@example.com"
sReadReceipt = true
sMsg = ""
On Error Resume Next
dim oMail, oConfig, oConfigFields
set oMail = Server.CreateObject("CDO.Message")
set oConfig = Server.CreateObject("CDO.Configuration")
set oConfigFields = oConfig.Fields
with oConfigFields
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = SMTPSendUsing
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPServerPort
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = SMTPUser
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = SMTPPassword
.Item("http://schemas.microsoft.com/cdo/configuration/sendtls") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Update
end with
oMail.Configuration = oConfig
oMail.Subject = sSubject
oMail.From = sFrom
oMail.To = sEmail
oMail.HTMLBody = sMailBody
oMail.Send
set oMail=nothing
sMsg = "Message Sent"
if Err.Number > 0 then sMsg = "ERROR: " & Err.Description
Response.Write sMsg
%>
If the test message was received by the email account with which you replaced recipient@example.com in the example shown above, you can now adapt the script to better fit your usage, such as by replacing the sSubject and sMailBody values.