Sending Mail from ASP with CDONTS.NewMail Object (DevASP)
NewMail object gives you the ability to send a message within an ASP page with only few lines of code. This article will help you understand different properties and methods of CDONTS.NewMail Object.
objNewMail.Send( [From] [, To] [, Subject] [, Body] )
You can create the instance of NewMail Object with the following code.
Dim objNewMail Set objNewMail = Server.CreateObject("CDONTS.NewMail")
Properties of NewMail Object.
||A string value contaning the email address of the sender
(for example Me@somewhere.com)
||A string value contaning the email address of the recipient.
(for example, firstname.lastname@example.org)
Multiple addresses can be added by seperating wih ";"
||The subject line for the message.
||A string value contaning the body text of message.
||A string contaning the email addresss of recipents who will recieve a copy of current message.
||A string contaning the email addresss of recipents who will recieve a blind copy of current message.
||This is an Integer value that represents the priority of message.
(for example High, Normal or Low)
||An integer value which sets the text format of NewMail Object.
ObjMail.BodyFormat = 0 (HTML format)
ObjMail.BodyFormat = 1 (default Plain Text format)
||An integer value which sets the encoding of NewMail Object.
ObjMail.MailFormat = 0 (Mime format)
ObjMail.MailFormat = 1 (default Plain Text format)
Methods of NewMail Object.
||This method attaches a file to the current mesage.
||This method attach a file to current message and associate a URL with that attachment.
||This method sends the message.
After the send method the NewMail object becomes invalid but stays in the memory.
You should set NewMail Object to nothing and relase the memory after the Send method.
After the send method you will have to create a new instance of NewMail Object if you want to send another message.
Let us see how we can use CDONTS.Newmail Object to send mail from an ASP Page.
' First create an instance of NewMail Object
Set objNewMail = Server.CreateObject("CDONTS.NewMail")
' After an instance of NewMail Object has been created.
' If you like you can use this one line of code to send the mail.
' objNewMail.Send From, To, Subject, Message
' or you can give every value seperate
objNewMail.From = "email@example.com"
objNewMail.To = "firstname.lastname@example.org"
' Please replace the "From" and "To" email addresses with your
' own valid email address. I recieve too many emails
' from people who test this sample and keep sending
' emails to email@example.com, or they keep the "From" property
' as firstname.lastname@example.org and I get response of
' undeliverable emails.
' NOTE: If the "To" or "From" properties of CDONTS contain
' invalid email address you will not recieve the email.
objNewMail.Subject = "This is a test Mail"
objNewMail.Body = "This is the Body text of this test mail."
' After the Send method, NewMail Object become Invalid
' You should set it to nothing to relase the memory
Set objNewMail = Nothing
' If you want to send another mail
' you have to create a new instance of NewMail Object again.
Response.Write "Email has been sent"