<%We then use the From property of the NewMail object to indicate the sender of the message. The From property is required, and multiple senders are not permitted. The type of this property is String.
Dim MyMail
Set MyMail = Server.CreateObject("CDONTS.NewMail")
%>
<%Analogously, we use the To property of the NewMail object to identify the recipients of the message. This property is also of type String. At least one of the To, Cc or Bcc properties (Cc and Bcc properties discussed subsequently) must be nonempty. Each recipient must be addressed in full, with multiple recipients separated by semicolons.
Dim MyMail
Set MyMail = Server.CreateObject("CDONTS.NewMail")
MyMail.From = "justme@myaddress.com"
%>
<%The Cc property (for indicating recipients of copies of the message) and Bcc property (for indicating recipients of blind copies) work exactly like the To property. Neither of these properties is required, however, and both are of String type.
Dim MyMail
Set MyMail = Server.CreateObject("CDONTS.NewMail")
MyMail.From = "justme@myaddress.com"
MyMail.To = "friend1@address1.com;friend2@address2.com"
%>
<%It is important to include a subject line in our email messages, so we do that next using the Subject property, which is of type String. This property is not required, however, and could be set to an empty string.
Dim MyMail
Set MyMail = Server.CreateObject("CDONTS.NewMail")
MyMail.From = "justme@myaddress.com"
MyMail.To = "friend1@address1.com;friend2@address2.com"
MyMail.Cc = "friend3@address3.com;friend4@address4.com"
MyMail.Bcc = "friend5@address5.com;friend6@address6.com"
%>
<%The BodyFormat property sets the text format of the NewMail object. It is of type Long, and has two possible values: 0, which indicates that the body of the message includes Hypertext Markup Language (HTML); or 1, which indicates that the body of the message is exclusively plain text. The default value for the BodyFormat property is 1, so this property does not need to be set for plain text messages. Our example message will be in plain text, but, for demonstration purposes, we will explicitly set the BodyFormat property.
Dim MyMail
Set MyMail = Server.CreateObject("CDONTS.NewMail")
MyMail.From = "justme@myaddress.com"
MyMail.To = "friend1@address1.com;friend2@address2.com"
MyMail.Cc = "friend3@address3.com;friend4@address4.com"
MyMail.Bcc = "friend5@address5.com;friend6@address6.com"
MyMail.Subject = "sending email via CDONTS NewMail"
%>
<%The MailFormat property sets the encoding for the NewMail object. It is of type Long, and has two possible values: 0, which indicates that the object is to be in MIME (Multipurpose Internet Mail Extension) format; or 1, which indicates that the object is to be in uninterrupted plain text. This property is optional, and its default value is 1. This property determines the default value for the EncodingMethod parameter in the AttachFile method (to be discussed later). Since we will be including an image attachment (later), we will set the MailFormat property to 0 now.
Dim MyMail
Set MyMail = Server.CreateObject("CDONTS.NewMail")
MyMail.From = "justme@myaddress.com"
MyMail.To = "friend1@address1.com;friend2@address2.com"
MyMail.Cc = "friend3@address3.com;friend4@address4.com"
MyMail.Bcc = "friend5@address5.com;friend6@address6.com"
MyMail.Subject = "sending email via CDONTS NewMail"
MyMail.BodyFormat = 1
%>
<%The Importance property (optional) allows us to set the importance associated with the NewMail object. Its type is Long, and the possible values are: 0, indicating low importance; 1, indicating normal importance (default); and 2, indicating high importance. Our message is very important, so we will set the Importance property accordingly.
Dim MyMail
Set MyMail = Server.CreateObject("CDONTS.NewMail")
MyMail.From = "justme@myaddress.com"
MyMail.To = "friend1@address1.com;friend2@address2.com"
MyMail.Cc = "friend3@address3.com;friend4@address4.com"
MyMail.Bcc = "friend5@address5.com;friend6@address6.com"
MyMail.Subject = "sending email via CDONTS NewMail"
MyMail.BodyFormat = 1
MyMail.MailFormat = 0
%>
<%To set the text of the NewMail object, we use the Body property, which can consist of plain text only, or can contain HTML (as described in the discussion of the BodyFormat property). The Body property is either of type String or Istream object (C/C++/Java only). The Body property is not required, so it is possible to send a message with no body text at all. In fact, if you really want to be mysterious, you can send a message with no subject and no body! We, however, have an important message to send, so we will provide text for the Body property.
Dim MyMail
Set MyMail = Server.CreateObject("CDONTS.NewMail")
MyMail.From = "justme@myaddress.com"
MyMail.To = "friend1@address1.com;friend2@address2.com"
MyMail.Cc = "friend3@address3.com;friend4@address4.com"
MyMail.Bcc = "friend5@address5.com;friend6@address6.com"
MyMail.Subject = "sending email via CDONTS NewMail"
MyMail.BodyFormat = 1
MyMail.MailFormat = 0
MyMail.Importance = 2
%>
<%If we wish to include an attachment with our mail message, we use the AttachFile method of the NewMail object. This method has three parameters.
Dim MyMail
Set MyMail = Server.CreateObject("CDONTS.NewMail")
MyMail.From = "justme@myaddress.com"
MyMail.To = "friend1@address1.com;friend2@address2.com"
MyMail.Cc = "friend3@address3.com;friend4@address4.com"
MyMail.Bcc = "friend5@address5.com;friend6@address6.com"
MyMail.Subject = "sending email via CDONTS NewMail"
MyMail.BodyFormat = 1
MyMail.MailFormat = 0
MyMail.Importance = 2
MyMail.Body = "Sending email with CDONTS NewMail" &_
"objects is easy! Try it!"
%>
<%At last, we are ready to use the NewMail object's Send method to send our email. After the Send method executes, the NewMail object becomes invalid and cannot be used for another message. Therefore, being conscientious programmers, we set that object to Nothing to release the memory. (We also do this because an accidental access of any kind to the NewMail object after Send executes will raise an embarrassing error!)
Dim MyMail
Set MyMail = Server.CreateObject("CDONTS.NewMail")
MyMail.From = "justme@myaddress.com"
MyMail.To = "friend1@address1.com;friend2@address2.com"
MyMail.Cc = "friend3@address3.com;friend4@address4.com"
MyMail.Bcc = "friend5@address5.com;friend6@address6.com"
MyMail.Subject = "sending email via CDONTS NewMail"
MyMail.BodyFormat = 1
MyMail.MailFormat = 0
MyMail.Importance = 2
MyMail.Body = "Sending email with CDONTS NewMail" &_
"objects is easy! Try it!"
MyMail.Attachfile "c:\path\smiley.gif", "smilefile.gif", 1
%>
<%That should do it!
Dim MyMail
Set MyMail = Server.CreateObject("CDONTS.NewMail")
MyMail.From = "justme@myaddress.com"
MyMail.To = "friend1@address1.com;friend2@address2.com"
MyMail.Cc = "friend3@address3.com;friend4@address4.com"
MyMail.Bcc = "friend5@address5.com;friend6@address6.com"
MyMail.Subject = "sending email via CDONTS NewMail"
MyMail.BodyFormat = 1
MyMail.MailFormat = 0
MyMail.Importance = 2
MyMail.Body = "Sending email with CDONTS NewMail" &_
"objects is easy! Try it!"
MyMail.Attachfile "c:\path\smiley.gif", "smilefile.gif", 1
MyMail.Send
Set MyMail = Nothing
%>
<%
Dim MyMail
Set MyMail = Server.CreateObject("CDONTS.NewMail")
MyMail.From = "justme@myaddress.com"
MyMail.To = "friend1@address1.com;friend2@address2.com"
MyMail.Cc = "friend3@address3.com;friend4@address4.com"
MyMail.Bcc = "friend5@address5.com;friend6@address6.com"
MyMail.Subject = "sending email via CDONTS NewMail"
MyMail.BodyFormat = 1
MyMail.MailFormat = 0
MyMail.Importance = 2
MyMail.Body = "Sending email with CDONTS NewMail" &_
"objects is easy! Try it!"
MyMail.Attachfile "c:\path\smiley.gif", "smilefile.gif", 1
MyMail.Send , "youtoo@youraddress.com", "new subject"
Set MyMail = Nothing
%>
Now that you know all
about the CDONTS NewMail object, let's look at how to put
this all together in a working user interface. We offer two
ways to do this. (Note: If you are viewing this tutorial from
a downloaded zip file, the links will not work.)
You can see an example of an
cdonts email submission form.
Or you can download a zip copy of
this tutorial and its supporting form-handling pages to see
how they work. Further you can easily customize these email
forms for your own needs.
Note, however, that our sample user interface does not provide
a means for the client to specify an attachment. This is because
the Request.Form method used to process the form is limited
in that it only allows plain text upload, and users often
wish to include attachments in alternative formats. If you
wish to add attachment capability and support it fully, the
Request.Form method must be augmented with additional software,
e.g. dgFileUpload.
[NOTE]
If you are using CDOSYS for Windows 2000 or Windows XP, the
code will be be slightly different, as shown below:
<%
Dim MyMail
Set MyMail = Server.CreateObject("CDO.Message")
MyMail.From = "justme@myaddress.com"
MyMail.To = "friend1@address1.com;friend2@address2.com"
MyMail.Cc = "friend3@address3.com;friend4@address4.com"
MyMail.Bcc = "friend5@address5.com;friend6@address6.com"
MyMail.Subject = "Sending Mail via CDOSYS for Windows 2000/XP"
MyMail.TextBody = "Sending email with CDOSYS Message " &_
"objects is easy! Try it!"
MyMail.AddAttachment "c:\path\smiley.gif"
MyMail.Fields("urn:schemas:httpmail:importance").Value = 2;
MyMail.Fields.Update()
MyMail.Send()
Set MyMail = Nothing
%>
[END
NOTE]
We hope our CDONTS NewMail tutorial has been helpful. Thanks
for browsing by, and, as usual, make sure to visit the Guru
often for our hottest tips and tutorials!