Microsoft Office Tutorials and References
In Depth Information
The general procedure for creating and sending an email message is as follows:
1.
Create a new MailItem object.
2.
Put the message text in the Body property (for plain text messages) or HTMLBody
property (for HTML format messages).
3.
Put the message subject in the Subject property.
4.
Put one or more recipients in the Recipients collection.
5.
Call the MailItem object’s Send() method.
The following sections look at some details.
Creating a New Message
As mentioned, creating a new message means creating a new MailItem object. However, you
cannot do this in the usual way using the New keyword. Rather, you must use the CreateItem()
method as shown here:
Dim msg As Outlook.MailItem
Set msg = CreateItem(olMailItem)
Once you have the new MailItem , you can address, compose, and send it.
Addressing the Message
Each recipient of a message is represented by a Recipient object. All message recipients are
placed in the MailItem object’s Recipients collection. This is true for regular “To” recipients
as well as CC and BCC recipients. Whether a given recipient is To, CC, or BCC is controlled by its
Type property.
To add a recipient to message, call the Add() method of the MailItem.Recipients collection
and pass it the recipient’s email address. This method returns a reference to the new recipient, which
you’ll need as I soon show you. Assume that msg refers to the new MailItem object created as
described in the previous section:
Dim recip As Outlook.Recipient
Set recip = msg.Recipients.Add(“someone@somewhere.net”)
By default, new recipients are considered “To” recipients. To change a recipient to CC or BCC, set
the Recipient.Type property to either of the named constants olCC or olBCC :
recip.Type = olCC
You can also add a recipient based on his or her display name as shown here:
Dim recip As Outlook.Recipient
Set recip = msg.Recipients.Add(“Jane Austin”)
Search JabSto ::




Custom Search