Send email from ASP

Send email from ASP with CDOSYS

CDOSYS email component replaced the old Microsoft's email component CDONTS. It is recommended now to use CDOSYS instead of CDONTS when emailing from ASP.

Here is how to use CDOSYS to send email from ASP:

<%

Set oMail = Server.CreateObject("CDO.Message")

Set oMailConfig = Server.CreateObject ("CDO.Configuration")

oMailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"

oMailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

oMailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

oMailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

oMailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

oMailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = "email@your-domain.com"

oMailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"

oMailConfig.Fields.Update

Set oMail.Configuration = oMailConfig

oMail.From = "your-email@your-domain.com"

oMail.To = "recipient@another-domain.com"

oMail.Subject = "Here goes the email subject..."

oMail.HTMLBody = "Here goes the email body..."

oMail.Send

Set oMail = Nothing

Set oMailConfig = Nothing

%>

Send email from ASP with CDONTS

Set ObjMail = Server.CreateObject("CDONTS.NewMail")

ObjMail.From = "your.name@yourdomain.com"

ObjMail.To = "somebody.else@theirdomain.com"

ObjMail.Subject = "Subject Text Here"

ObjMail.Body = "Body Text Here"

ObjMail.Send

Set ObjMail = Nothing

Send email from ASP with Jmail

Set mail = CreateObject ("JMail.SMTPMail")

mail.ServerAddress = smtpServer & ":" & smtpPort

mail.Sender = sender

mail.Subject = subject

mail.AddRecipient receiver

mail.ContentType = "text/html" ' or you can put 'text/plain' for plain text email

mail.ISOEncodeHeaders = false

mail.ContentTransferEncoding = "8bit"

mail.Body = body

Connect to MS SQL Server database from ASP

Before you can access your MS SQL Server database from ASP, you need to connect to it using one of the following methods:

1. Connect to a MS SQL Server database with OLE DB:

Set objConn = Server.CreateObject("ADODB.Connection")

objConn.Open "Provider=SQLOLEDB; Data Source=YOUR_SERVER_NAME; Initial

Catalog=your_database_name; User ID=your_username; Password=your_password"

objConn.Close

Set objConn = Nothing

2. Connect to a MS SQL Server database with SQL Driver:

Set objConn = Server.CreateObject("ADODB.Connection")

objConn.Open "Driver={SQL Server};" & _

"Server=YOUR_SERVER_NAME;" & _

"Database=your_database_name;" & _

"Uid=your_username;" & _

"Pwd=your_password;"

objConn.Close

Set objConn = Nothing

Was this answer helpful?

 Print this Article