MailBee.NET Objects 8.0

AttachmentCollection.AddMethod(String, String, String, String, HeaderCollection, NewAttachmentOptions, MailTransferEncoding)

Adds the attachment from a file.

publicboolAdd(
stringfilename,
stringtargetFilename,
stringcontentID,
stringcontentType,
HeaderCollectioncustomHeaders,
NewAttachmentOptionsoptions,
MailTransferEncodingmailEnc
);

Parameters

filename
The absolute or relative path to the file which should be attached.
targetFilename
The filename of the attachment as it should appear in the mail message. If a null reference (Nothing in Visual Basic), MailBee will take it from filename parameter value. If an empty string, the attachment will have no name.
contentID
The content identifier (CID) of the attachment (for inline attachments), or empty string if the attachment is not inline.
contentType
The content type of the attachment, or a null reference (Nothing in Visual Basic) to let MailBee detect the content type automatically.
customHeaders
The collection of the headers which should be included into the header section in additon to the standard attachment headers. If a null reference (Nothing in Visual Basic), no custom headers will be added.
options
The options which affect how the attachment is added.
mailEnc
The mail encoding to use when placing the attachment data into the message.

Return Value

true if the attachment was successfully added to the collection; otherwise, false.

Remarks

The targetFilename parameter allows the developer to override the filename under which the attachment will be added to the collection. This is useful when the developer wants to add the attachment from a temporary file such as ETQB4914.TMP under meaningful name such as report.doc.

Exceptions

Exception Type Condition
MailBeeInvalidArgumentException filename is a null reference (Nothing in Visual Basic) or an empty string.
MailBeeIOException An error occurred and ThrowExceptions is true.

Example

This sample creates a new message and adds an attachment to this message.

[C#]
// To use the code below, import MailBee namespaces at the top of your code.
using MailBee;
using MailBee.Mime;

// The actual code (put it into a method of your class)

// Create a new MailMessage object.
MailMessage msg = new MailMessage();

// Add the attachment to the message.
msg.Attachments.Add(@"C:\Docs\mypic.gif", "my.gif", "<00s4a8m8918c$5664i1b1$iw671781@tlffmdqjobxj>", "image/gif", null, NewAttachmentOptions.None, MailTransferEncoding.Base64);
[VisualBasic]
' To use the code below, import MailBee namespaces at the top of your code.
Imports MailBee
Imports MailBee.Mime

' The actual code (put it into a method of your class)

' Create a new MailMessage object.
Dim msg As New MailMessage

' Add the attachment to the message.
msg.Attachments.Add("C:\Docs\mypic.gif", "my.gif", "<00s4a8m8918c$5664i1b1$iw671781@tlffmdqjobxj>", "image/gif", Nothing, NewAttachmentOptions.None, MailTransferEncoding.Base64)

See Also

AttachmentCollection Class | MailBee.Mime Namespace | AttachmentCollection.Add Overload List | Attachment