O'Reilly logo

CDO & MAPI Programming with Visual Basic: by Dave Grundgeiger

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Sending File Attachments

MAPI defines four types of attachments: file, reference to a file, OLE object, and embedded message.

CDO handles all four types of attachments easily. To add an attachment to a message, use the Add method of the Message object’s Attachments collection:

' (CdoMessage previously Dim'ed and Set)

Dim CdoAttachments As MAPI.Attachments
Dim CdoAttachment As MAPI.Attachment

Set CdoAttachments = CdoMessage.Attachments
Set CdoAttachment = CdoAttachments.Add(Name:="autoexec.bat", _
   Position:=-1, Type:=CdoFileData, Source:="c:\autoexec.bat")

The syntax of the Add method is:

Set CdoAttachment = CdoAttachments.Add([Name][, Position][, Type][, Source])

The method returns a reference to the newly created Attachment object. The method’s parameters are:

Name

The display name to be used by the receiving mail client when representing the attachment in its UI. When the attachment is a file, the name should be the filename, including its extension. The receiving mail client may default to this name when copying the data from its message store to the local file system. (Some clients may instead default to the filename portion of the Source parameter.)

Position

The character position within the body of the message at which the attachment should appear. Some email client applications display a representation of the attachment within the body of the message at the character position indicated by Position. (However, some ignore this value and display the attachments separately.) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required