AttachmentCollection.Add Method (MailMessage, String, String, String, HeaderCollection, NewAttachmentOptions, MailTransferEncoding)
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.Mime
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 11.2.0 build 590 for .NET 4.5
Syntax
public void Add(
	MailMessage message,
	string targetFilename,
	string contentID,
	string contentType,
	HeaderCollection customHeaders,
	NewAttachmentOptions options,
	MailTransferEncoding mailEnc
)

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
ExceptionCondition
MailBeeInvalidArgumentExceptionmessage is a null reference (Nothing in Visual Basic).
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.
Examples
The following example demonstrates how a mail message can be attached to another mail message.
// 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)

// Load the message from file.
MailMessage messageToAttach = new MailMessage();
messageToAttach.LoadMessage(@"C:\Docs\TestMail.eml");

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

// Set plain text body of the message.
msg.BodyPlainText = "Hello, World!";

// Add the attachment to the message.
msg.Attachments.Add(messageToAttach, "original.eml", "", "message/rfc822", null, NewAttachmentOptions.Inline, MailTransferEncoding.None);

// Save message to disk.
msg.SaveMessage(@"C:\Temp\forwarded.eml");
See Also