Adds the specified Attachment object to the collection.
| Exception Type | Condition |
|---|---|
| MailBeeInvalidArgumentException | attach is a null reference (Nothing in Visual Basic). |
This sample loads two messages from .EML files, adds all attachments of the second message to the first message, and saves the first message (which now includes all the original plus added attachments) to disk.
[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) MailMessage msg1 = new MailMessage(); msg1.LoadMessage(@"C:\Docs\TestMail1.eml"); MailMessage msg2 = new MailMessage(); msg2.LoadMessage(@"C:\Docs\TestMail2.eml"); for (int i = 0; i < msg2.Attachments.Count; i++) { msg1.Attachments.Add(msg2.Attachments[i]); } msg1.SaveMessage(@"C:\Temp\TestMail1.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) Dim msg1 As New MailMessage msg1.LoadMessage("C:\Docs\TestMail1.eml") Dim msg2 As New MailMessage msg2.LoadMessage("C:\Docs\TestMail2.eml") Dim i As Integer For i = 0 To msg2.Attachments.Count - 1 msg1.Attachments.Add(msg2.Attachments(i)) Next msg1.SaveMessage("C:\Temp\TestMail1.eml")
AttachmentCollection Class | MailBee.Mime Namespace | AttachmentCollection.Add Overload List | Attachment