How to Send Email Using ASP
Before create any email method, first you make sure that what email component your web server is using. There are mainly four types of email components are used from one web server to another depending on what method is applicable on that particular server. The below code explains all the four methods available till date:
- Server.CreateObject("Persists.MailSender") - ASP Email
- Server.CreateObject("SMTPsvg.Mailer") - ASP Email
- Server.CreateObject("CDONTS.Newmail") - CDONTS Mail
- Server.CreateObject("JMail.SMTPMail") - Jmail
Send ASP Email Using Persists.MailSender
Set Mail = Server.CreateObject("Persits.MailSender")
Mail.Host = "mail.smtp-server.com" // Supply Valid SMTP Server
Mail.From = "email-id@domain-name.com" // Supply Senders Email Address
Mail.FromName = "Senders Name" // Optionally Supply Senders Name
Mail.AddAddress "email-id@domain-name.com", "Optional Recipient Name" // Supply Recipient Email
Mail.AddCc = "other-email@domain-name.com"
Mail.AddBcc = "other-email@domain-name.com"
Mail.AddAttachment = "c:\images\logo.jpg" // Supply an Attachment Path
Mail.Subject = "Write Your Subject Line Here"
Mail.Body = "Please Enter The Message Body Here."
// OR
Mail.Body = "Send mail in HTML format. Place HTML code here."
Mail.IsHTML = true
Mail.Send // Finally, Send Email
Send ASP Mail Using SMTPsvg.Mailer
set Mail = Server.CreateObject("SMTPsvg.Mailer")
Mail.RemoteHost = "mail.smtp-server.com" // Supply a Valid SMTP Server
Mail.FromAddress = "email-id@domain-name.com" // Supply Sender's Email Address (only one)
Mail.FromName = "Senders Name" // Optionally Supply Sender's Name
Mail.AddRecipient "Recipients Name", "email-id@domain-name.com" // Supply Recipient Name and Email-id
Mail.AddCc "Other Recipients Name", "other-email@domain-name.com"
Mail.Bcc = "other-email@domain-name.com"
Mail.AddAttachment = "c:\images\logo.jpg" // Supply an Attachment Path
Mail.Subject = " Write Your Subject Line Here"
Mail.BodyText = " Please Enter The Message Body Here."
// OR
Mail.BodyText = "Send mail in HTML format. Place HTML code here. "
Mail.ContentType = "text/html"
Mail.SendMail // Finally, Send Email
Send Send Mail Using CDONTS.Newmail
set Mail = Server.CreateObject("CDONTS.Newmail")
Mail.From = "email-id@domain-name.com" // Supply Senders Email Address (only one)
Mail.To = "email-id@domain-name.com" // Use ; for separating recipients list
Mail.Cc = "other-email@domain-name.com"
Mail.Bcc = "other-email@domain-name.com"
Mail.AttachFile = "c:\images\logo.jpg" // Supply an Attachment Path
Mail.Subject = "Write Your Subject Line Here"
Mail.Body = "Please Enter The Message Body Here."
// OR
Mail.Body = "Send mail in HTML format. Place HTML code here."
Mail.BodyFormat = 0
Mail.Send // Finally, Send Email
Send Email Using JMail.SMTPMail
set Mail = Server.CreateObject("JMail.SMTPMail")
Mail.ServerAddress = "mail.smtp-server.com" // Supply a Valid SMTP Server
Mail.From = "email-id@domain-name.com" // Supply Sender's Email Address (only one)
Mail.FromName = "Senders Name" // Optionally Supply Sender's Name
Mail.AddRecipient = " email-id@domain-name.com ", "Optional Recipients Name" // Supply Recipient Email
Mail.AddRecipientCC = "other-email@domain-name.com"
Mail.AddRecipientBCC = "other-email@domain-name.com"
Mail.AddAttachment = "c:\images\logo.jpg" // Supply an Attachment Path
Mail.Subject = "Write Your Subject Line Here"
Mail.Body = "Please Enter The Message Body Here."
// OR
Mail.AppendHTML = "Send mail in HTML format. Place HTML code here. "
Mail.BodyFormat = 0
Mail.Execute // Finally, Send Email