Sending Email with Classic ASP Scripts
Posted on 08.05.09 23:32:47 by Ariel G. Saputra in Classic ASP
There are several email components for classic asp available out there, if you not sure about which components are installed in your server, just ask your technical support. CDOsys is the default email component for microsoft SMTP server running together with IIS Web Server, or CDONT for prior SMTP version but mostly hosting providers also install commercial email component like ASPEmail, JMail, MailEnable etc.
Below are some samples of scripts to send an email with Classic ASP:
Classic ASP email with CDO.Message
Set cdoConfig = CreateObject("CDO.Configuration")
With cdoConfig.Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServerPort) = 25
.Item(cdoSMTPconnectiontimeout) = 10
.Item(cdoSMTPServer) = "mail.server.com"
.Item(cdoSMTPAuthenticate) = 1
.Item(cdoSendUsername) = "username"
.Item(cdoSendPassword) = "password"
.Update
End With
Set cdoMessage = CreateObject("CDO.Message")
With cdoMessage
Set .Configuration = cdoConfig
.From = "user@company.com"
.To = "target@company.com"
.Subject = "Sample CDO Message"
.HTMLBody = "<html><head><title></title><body>Testing Email</body></html>"
.AddAttachment "c:someimage.jpg"
.cdoImportance = 1
.cdoPriority = 0
.Send
End With
Set cdoMessage = Nothing
Set cdoConfig = Nothing
Classic ASP email with CDONTs
Set oCDONTS = CreateObject("CDONTS.NewMail")
oCDONTS.From = "user@company.com"
oCDONTS.To = "target@company.com"
oCDONTS.Cc = "target2@company.com"
oCDONTS.Subject = "Sample CDONT Message"
oCDONTS.AttachFile Server.MapPath("c:someimage.jpg")
oCDONTS.BodyFormat=0
oCDONTS.MailFormat=0
oCDONTS.Body= "<html><head><title></title><body>Testing Email</body></html>"
oCDONTS.Send
set oCDONTS=nothing
Classic ASP email with ASPEmail
Set oPersitMail = Server.CreateObject("Persits.MailSender")
oPersitMail.IsHTML = true
oPersitMail.Priority = 1
oPersitMail.Host = "mail.server.com"
oPersitMail.From = "user@company"
oPersitMail.FromName = "name"
oPersitMail.AddAddress = "target@company"
oPersitMail.AddCC "target2@company"
oPersitMail.AddAttachment "c:someimage.jpg"
oPersitMail.Subject = "Sample Persits Mail"
oPersitMail.Body = "<html><head><title></title><body>Testing Email</body></html>"
oPersitMail.Send
Set oPersitMail = Nothing
more information about persits ASPEmail could be found at ASPEmail’s Website
Classic ASP email with JMail
Set oJMail = Server.CreateObject("JMail.SMTPMail")
with oJMail
.Sender = "user@company.com"
.SenderName = "name"
.AddRecipient "target@company"
.AddRecipientCC "target2@company"
.Subject = "Test JMail Message"
.Priority = 1
.Body = "Sample text body"
.HTMLBody = "<html><head><title></title><body>Testing Email</body></html>"
.AddAttachment "C:someimage.jpg"
end with
oJMail.ServerAddress = "mail.company.com:25"
oJMail.Execute
Set oJMail = Nothing
more information about JMail could be found at Dimac.net
Classic ASP email with MailEnable
oMeMail = server.CreateObject("MEMail.message")
oMeMail.Server = "mail.company.com"
oMeMail.ServerPort = 25
oMeMail.Username = "username"
oMeMail.Password = "password"
oMeMail.From = "user@company.com"
oMeMail.FromDisplayName = "Display Name"
oMeMail.MailTo = "target@company"
oMeMail.MailCC = "target2@company;target3@company.com"
oMeMail.Subject = "Test MailEnable"
oMeMail.ContentType = "text/html"
oMeMail.MessageBody = "<html><hrad><title></title></head><body>Testing Email</body></html>"
oMeMail.Attachmentfilename = "c:someimage.jpg"
oMeMail.Attachmentname = "image.zip"
oMeMail.SendMessage
set oMeMail = Nothing
visit mailenable.com for detail documentation
Classic ASP email with ServerObjects AspMail
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromName = "Name."
Mailer.FromAddress= "user@company.com"
Mailer.RemoteHost = "mail.company.com"
Mailer.AddRecipient "target name", "target@company.com"
Mailer.AddCC "target2 name", "target2@company.com"
Mailer.Subject = "Sample AspMail"
Mailer.ContentType = "text/html"
Mailer.BodyText = "<html><body>testing email</body></html>"
Mailer.SendMail
Set Mailer = nothing
visit serverobjects.com for detail documentation
Classic ASP email with EasyMail
Set SMTP = CreateObject("EasyMail.SMTP.6")
SMTP.MailServer = "mail.company.com"
SMTP.Subject = "Sample EasyMail"
SMTP.BodyText = "Testing EasyMail"
SMTP.FromAddr = "user@company.com"
SMTP.AddRecipient "target", "target@company", 1
SMTP.AddAttachment("c:someimage.jpg", 0)
SMTP.Send
Set SMTP = Nothing
visit quiksoft.com for detail documentation
