AttachmentCollectionAdd Method (String, String, HeaderCollection, MailTransferEncoding)
Adds text-only part with the specified content-type.

Namespace: MailBee.Mime
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
Syntax
public void Add(
	string data,
	string contentType,
	HeaderCollection customHeaders,
	MailTransferEncoding mailEnc
)

Parameters

data
Type: SystemString
Text to be inserted as part's body.
contentType
Type: SystemString
Content-Type of the part being added.
customHeaders
Type: MailBee.MimeHeaderCollection
The collection of the headers which should be included into the header section in additon to the Content-Type. If a null reference (Nothing in Visual Basic), no custom headers will be added.
mailEnc
Type: MailBee.MimeMailTransferEncoding
The content-transfer encoding to be used. Usually, None.
Remarks

This overload can typically be used to add such MIME parts as delivery-status reports (Message Disposition Notification, MDN). For MDNs, you usually supply "message/delivery-status" as contentType value and None as mailEnc value.

The only mandatory header which will be added is Content-Type (unless you added some custom headers). No "attachment" marker will be added.

Note Note
Text lines in data which have more than 76 chars will be explicitly wrapped by defaut (unless QuotedPrintable or Base64 is selected, they can handle wrapping internally). You can adjust this behavior by increasing UnwrappedLineLengthLimit property value.
Examples
This sample prepares a Message Disposition Notification e-mail.
MailMessage msg = new MailMessage();
string mdnBody = @"Reporting-MTA: dns;mx.company.com
Received-From-MTA: dns;servo01.domain.net
Arrival-Date: Wed, 18 May 2016 08:28:53 +0000

Original-Recipient: rfc822;jdoe@company.com
Final-Recipient: rfc822;jdoe@company.com
Action: failed
Status: 5.1.10
Diagnostic-Code: smtp;550 5.1.10 RESOLVER.ADR.RecipientNotFound;
 Recipient not found by SMTP address lookup
";
msg.Attachments.Add(mdnBody, "message/delivery-status", null, MailTransferEncoding.None);
msg.MdnReportType = "delivery-status";
msg.From.AsString = "Internet Mail Delivery <postmaster@company.com>";
msg.Subject = "Delivery Notification: Delivery has failed";
msg.To.Add("sender@domain.net");
msg.BodyPlainText = @"Your message to jdoe@company.com couldn't be delivered.
jdoe@company.com wasn't found at company.com.
";
msg.SaveMessage(@"C:\Temp\mdn.eml"); // Or assign msg to Message property of Smtp object to send it out.
Dim msg As New MailMessage() Dim mdnBody As String = "Reporting-MTA: dns;mx.company.com" & vbCrLf & _ "Received-From-MTA: dns;servo01.domain.net" & vbCrLf & _ "Arrival-Date: Wed, 18 May 2016 08:28:53 +0000" & vbCrLf & vbCrLf & _ "Original-Recipient: rfc822;jdoe@company.com" & vbCrLf & _ "Final-Recipient: rfc822;jdoe@company.com" & vbCrLf & _ "Action: failed" & vbCrLf & _ "Status: 5.1.10" & vbCrLf & _ "Diagnostic-Code: smtp;550 5.1.10 RESOLVER.ADR.RecipientNotFound;" & vbCrLf & _ " Recipient not found by SMTP address lookup" & vbCrLf msg.Attachments.Add(mdnBody, "message/delivery-status", Nothing, MailTransferEncoding.None) msg.MdnReportType = "delivery-status" msg.From.AsString = "Internet Mail Delivery <postmaster@company.com>" msg.Subject = "Delivery Notification: Delivery has failed" msg.To.Add("sender@domain.net") msg.BodyPlainText = "Your message to jdoe@company.com couldn't be delivered." & vbCrLf & vbCrLf & _ "jdoe@company.com wasn't found at company.com." & vbCrLf msg.MailTransferEncodingPlain = MailTransferEncoding.None msg.SaveMessage("C:\Temp\mdn.eml") ' Or assign msg to Message property of Smtp object to send it out.
See Also