AttachmentCollectionAdd Method (MailMessage, String, String, String, HeaderCollection, NewAttachmentOptions, MailTransferEncoding) |
Adds the specified the
MailMessage as attachment (i.e. forwards that message as attachment).
Namespace: MailBee.MimeAssembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax public void Add(
MailMessage message,
string targetFilename,
string contentID,
string contentType,
HeaderCollection customHeaders,
NewAttachmentOptions options,
MailTransferEncoding mailEnc
)
Public Sub Add (
message As MailMessage,
targetFilename As String,
contentID As String,
contentType As String,
customHeaders As HeaderCollection,
options As NewAttachmentOptions,
mailEnc As MailTransferEncoding
)
Parameters
- message
- Type: MailBee.MimeMailMessage
The mail message to be added as attachment. - targetFilename
- Type: SystemString
The filename under which to add the attachment into the collection.
If a null reference (Nothing in Visual Basic), MailBee will take it from the Subject
of the message being attached. 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. If a null reference (Nothing in Visual Basic), message/rfc822 value is used. - 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.
Exceptions Remarks
This method can be used to forward mail messages with another mail message. To forward a single message,
it's easier to use
ForwardAsAttachment method.
Note |
---|
Be sure to use as None as mailEnc value. Some mail services
cannot decode attached emails if they are Base64-encoded. |
Examples The following example demonstrates how a mail message can be attached to another mail message.
using MailBee;
using MailBee.Mime;
MailMessage messageToAttach = new MailMessage();
messageToAttach.LoadMessage(@"C:\Docs\TestMail.eml");
MailMessage msg = new MailMessage();
msg.BodyPlainText = "Hello, World!";
msg.Attachments.Add(messageToAttach, "original.eml", "", "message/rfc822", null, NewAttachmentOptions.Inline, MailTransferEncoding.None);
msg.SaveMessage(@"C:\Temp\forwarded.eml");
Imports MailBee
Imports MailBee.Mime
Dim messageToAttach As New MailMessage
messageToAttach.LoadMessage("C:\Docs\TestMail.eml")
Dim msg As New MailMessage
msg.BodyPlainText = "Hello, World!"
msg.Attachments.Add(messageToAttach, "original.eml", "", "message/rfc822", Nothing, NewAttachmentOptions.Inline, MailTransferEncoding.None)
msg.SaveMessage("C:\Temp\forwarded.eml")
See Also