TextBodyPartCollectionAdd Method (String, HeaderCollection, Boolean)
Creates a new text body part having the specified parameters and appends it to the collection.

Namespace: MailBee.Mime
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.2.0 build 630 for .NET 4.5
public TextBodyPart Add(
	string contentType,
	HeaderCollection customHeaders,
	bool noDefaultHeaders


Type: SystemString
A string specifying the content type of the text part to be created.
Type: MailBee.MimeHeaderCollection
A reference to the collection of user-defined headers to be placed into the header section of the text part, a null reference (Nothing in Visual Basic) if no user-defined headers available.
Type: SystemBoolean
Indicates whether to add the standard headers.

Return Value

Type: TextBodyPart
A reference to the newly added text body part.
MailBeeInvalidArgumentExceptioncontentType is a null reference (Nothing in Visual Basic) and noDefaultHeaders is false.
By default, the newly created text part will contain Content-Type and (optionally) Content-Transfer-Encoding headers. If noDefaultHeaders was true, these headers will not be added and contentType value will be ignored.
This sample creates a new message, sets plain-text body and alternative XML body with user-defined header, and saves it to disk.
// 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)

// Create a message and set plain-text body.
MailMessage msg = new MailMessage();
msg.BodyPlainText = "See XML body";

// Prepare custom headers for XML part.
HeaderCollection userDefined = new HeaderCollection();
userDefined.Add("Content-Class", "document", true);

// Create XML part and set its contents.
msg.BodyParts.Add("text/xml", userDefined, false).Text = "<?xml version=\"1.0\" ?>";

// Save the message to disk.
See Also