Adds the specified the MailMessage as attachment (i.e. forwards that message as attachment).
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.
| Exception Type | Condition |
|---|---|
| MailBeeInvalidArgumentException | message is a null reference (Nothing in Visual Basic). |
The following example demonstrates how a mail message can be attached to another mail 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) // 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, "1.eml", "", "message/rfc822", null, NewAttachmentOptions.None, MailTransferEncoding.None); // Save message to disk. msg.SaveMessage(@"C:\Temp\TestEmail.eml");
[Visual Basic] ' 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) ' Load the message from file. Dim messageToAttach As New MailMessage messageToAttach.LoadMessage("C:\Docs\TestMail.eml") ' Create new MailMessage object. Dim msg As New MailMessage ' Set plain text body of the message. msg.BodyPlainText = "Hello, World!" ' Add the attachment to the message. msg.Attachments.Add(messageToAttach, "1.eml", "", "message/rfc822", Nothing, NewAttachmentOptions.None, MailTransferEncoding.None) ' Save message to disk. msg.SaveMessage("C:\Temp\TestEmail.eml")
AttachmentCollection Class | MailBee.Mime Namespace | AttachmentCollection.Add Overload List | Attachment | MailMessage