AttachmentCollectionAdd Method (String, String, String, String, HeaderCollection, NewAttachmentOptions, MailTransferEncoding) |
Adds the attachment from a file.
Namespace: MailBee.MimeAssembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax public bool Add(
string filename,
string targetFilename,
string contentID,
string contentType,
HeaderCollection customHeaders,
NewAttachmentOptions options,
MailTransferEncoding mailEnc
)
Public Function Add (
filename As String,
targetFilename As String,
contentID As String,
contentType As String,
customHeaders As HeaderCollection,
options As NewAttachmentOptions,
mailEnc As MailTransferEncoding
) As Boolean
Parameters
- filename
- Type: SystemString
The absolute or relative path to the file which should be attached. - targetFilename
- Type: SystemString
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
- Type: SystemString
The content identifier (CID) of the attachment (for inline attachments), or empty string
if the attachment is not inline. - contentType
- Type: SystemString
The content type of the attachment, or a null reference (Nothing in Visual Basic) to let MailBee
detect the content type automatically. - customHeaders
- Type: MailBee.MimeHeaderCollection
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
- Type: MailBee.MimeNewAttachmentOptions
The options which affect how the attachment is added. - mailEnc
- Type: MailBee.MimeMailTransferEncoding
The mail encoding to use when placing the attachment data into the message.
Return Value
Type:
Booleantrue if the attachment was successfully added to the collection; otherwise,
false.
Exceptions 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.
Note |
---|
If you're attaching another e-mail message, be sure to use as None as mailEnc value. Some mail services
cannot decode attached emails if they are Base64-encoded. |
Examples This sample creates a new message and adds an attachment to this message.
using MailBee;
using MailBee.Mime;
MailMessage msg = new MailMessage();
msg.Attachments.Add(@"C:\Docs\mypic.gif", "my.gif", "<00s4a8m8918c$5664i1b1$iw671781@tlffmdqjobxj>", "image/gif", null, NewAttachmentOptions.None, MailTransferEncoding.Base64);
Imports MailBee
Imports MailBee.Mime
Dim msg As New MailMessage
msg.Attachments.Add("C:\Docs\mypic.gif", "my.gif", "<00s4a8m8918c$5664i1b1$iw671781@tlffmdqjobxj>", "image/gif", Nothing, NewAttachmentOptions.None, MailTransferEncoding.Base64)
See Also