Add Method (Attachments collection)

Dundas

Add Method (Attachments collection)

Adds an Attachment object to the Attachments collection.

Syntax

AttachmentsCollection.Add (FileName as string, [ContentName as string = FileName, ContentType as string = "Application/Octet-stream", EncodingType as string = "BASE64", CharSet as string = "US-ASCII", CustomHeaders as string = ""])

The Add method syntax has the following parts:

Part

Description

FileName

The full pathname of the file to be added.

ContentName

The name by which the attachment will be referred to in the client's email software.

ContentType

Specifies the media type and subtype of data in the body of the message.

EncodingType

The type of encoding to be used for the attachment. Must be uppercase.

CharSet

The character set to be used.

CustomHeaders

Any custom header to be added to the attachment.

  Remarks

Use this method to add an Attachment object to the Attachments collection. To remove an Attachment use the Remove method. To remove all Attachments from the collection call the Clear method.

To send multiple attachments just add the desired file attachments to this collection and call the SendMail method.

If you do not specify a value for the ContentName property then the client email software will reference the attachment by using the FileName parameter.

To add a custom header to the attachment use the CustomHeaders argument.

The Content-Type header field (represented by the ContentType argument) is used to specify the nature of the data in the attachment. It uses type and subtype identifiers in the format of "type/sub-type" (e.g. text/html, text/plain, etc.) and also provides auxiliary information that may be required for certain types. After the type and subtype names the remainder of the header field is simply a set of parameters, specified in an attribute/value notation. These parameters differ for different types, and the ordering of the parameters is not important. Among the defined arguments is a "charset" parameter which determines the character set to be used for the attachment. Comments are allowed in accordance with RFC 822, and the rules for structured header fields may be found in RFC 2046.

The CharSet argument determines the character set to be used for the attachment. This parameter is not case sensitive.

The two supported encoding types (as specified by the EncodingType argument) are "BASE64" and "QUOTEDPRINTABLE". If you want to explicitly set the EncodingType parameter then keep in mind that it must be uppercase, and the value of this argument is used for the value of the "Content-Transfer-Encoding" header. If an invalid type is specified then "BASE64" is used. You may want to use "QUOTEDPRINTABLE" if the attachment content can be represented with ASCII characters. For more information about the "Content-Transfer-Encoding" header refer to RFC 2045.

If you are using the Dundas Upload control you can loop through all items in the the Upload control's Files collection and add each UploadedFile object to the Mailer control's Attachments collection. The uploaded files will then be sent along with the email as attachments. The ContentType of the UploadedFile will be used for the ContentType of the Attachment object unless you set this argument explicitly. See Tutorial 1: Sending an Email with an Attachment for sample code which demonstrates using the Upload control in conjunction with the Mailer control. You can also refer to the Upload control's tutorials for further code samples and instructions.

See Also: Attachments Collection | Clear Method | Count Property | Item Method | Remove Method