Sending File References

If the sender and receiver have access to a common file system (perhaps they’re on the same LAN), it’s not necessary to transport a file’s contents with the message; it will suffice simply to specify the file’s path and filename. The CdoFileLink attachment type is used for this purpose. For example:

' (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:=CdoFileLink, _
   Source:="\\daveg\c2\autoexec.bat")

Note that the Source parameter specifies the path in UNC format.

Be aware that there is a difference between a file reference as defined by MAPI and a shortcut as defined by the 32-bit Windows operating systems. In Windows, a shortcut is a file, having a .lnk extension, that provides a link to another file. Shortcut files, just like other files, can be sent as attachments to email messages, thereby providing another means of sending a file reference rather than the file itself. The shortcut must link to a file that is accessible to the receiving system. To send a shortcut file, specify the Type parameter as CdoFileData, and set the Name and Source parameters based on the .lnk file.

Get CDO & MAPI Programming with Visual Basic: now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.