AttachFile Method (CDONTS NewMail Object)

Exchange Server 2003

Topic Last Modified: 2004-06-09

The AttachFile method adds an attachment to the message by reading a file.

        objNewMail.AttachFile(Source [, FileName] [, EncodingMethod] ) 


Required. This NewMail object.


Required. IStream object or String. The full path and file name of the file to be attached to the message, or a pointer to an IStream object containing the file data.


Optional. String. The file name to appear in the attachment's placeholder in the message. If FileName is not supplied, the file name from the Source parameter is used.


Optional. Long. The manner of encoding the attachment. The following values are possible:

EncodingMethod setting





The attachment is to be in UUEncode format (default).



The attachment is to be in base 64 format.

The default value for the EncodingMethod parameter can change if you set the MailFormat property. If MailFormat is set to CdoMailFormatText, the default value is CdoEncodingUUencode. If MailFormat is set to CdoMailFormatMime, the default value is CdoEncodingBase64. However, if you add an attachment encoded in base 64 format, the value of the MailFormat property is automatically set to CdoMailFormatMime.

Only C/C++ and Java programs can use an IStream object for the Source parameter. They should pass an IUnknown object that returns an IStream interface in response to QueryInterface. Microsoft® Visual Basic® supports the IDispatch interface and not IUnknown, so it cannot use an IStream object.