PeterO.Mail.Message

## PeterO.Mail.Message

public sealed class Message

Represents an email message, and contains methods and properties for accessing and modifying email message data. This class implements the Internet Message Format (RFC 5322) and Multipurpose Internet Mail Extensions (MIME; RFC 2045-2047, RFC 2049).

Thread safety: This class is mutable; its properties can be changed. None of its instance methods are designed to be thread safe. Therefore, access to objects from this class must be synchronized if multiple threads can access them at the same time.

The following lists known deviations from the mail specifications (Internet Message Format and MIME):

It would be appreciated if users of this library contact the author if they find other ways in which this implementation deviates from the mail specifications or other applicable specifications.

This class currently doesn’t support the “padding” parameter for message bodies with the media type “application/octet-stream” or treated as that media type (see RFC 2046 sec. 4.5.1).

In this implementation, if the content-transfer-encoding “quoted-printable” or “base64” occurs in a message or body part with content type “multipart/” or “message/” (other than “message/global”, “message/global-headers”, “message/global-disposition-notification”, or “message/global-delivery-status”), that encoding is treated as unrecognized for the purpose of treating that message or body part as having a content type of “application/octet-stream” rather than the declared content type. This is a clarification to RFCs 2045 and 2049. (This may result in “misdecoded” messages because in practice, most if not all messages of this kind don’t use quoted-printable or base64 encodings for the whole body, but may do so in the body parts they contain.)

This implementation can decode an RFC 2047 encoded word that uses ISO-2022-JP or ISO-2022-JP-2 (encodings that use code switching) even if the encoded word’s payload ends in a different mode from “ASCII mode”. (Each encoded word still starts in “ASCII mode”, though.) This, however, is not a deviation to RFC 2047 because the relevant rule only concerns bringing the output device back to “ASCII mode” after the decoded text is displayed (see last paragraph of sec. 6.2) – since the decoded text is converted to Unicode rather than kept as ISO-2022-JP or ISO-2022-JP-2, this is not applicable since there is no such thing as “ASCII mode” in the Unicode Standard.

Note that this library (the MailLib library) has no facilities for sending and receiving email messages, since that’s outside this library’s scope.

Member Summary

### Message Constructor

public Message(
    byte[] bytes);

Initializes a new instance of the PeterO.Mail.Message class. Reads from the given byte array to initialize the email message.

Remarks:This constructor parses an email message, and extracts its header fields and body, and throws a MessageDataException if the message is malformed. However, even if a MessageDataException is thrown, it can still be possible to display the message, especially because most email malformations seen in practice are benign in nature (such as the use of very long lines in the message). One way an application can handle the exception is to display the message, or part of it, as raw text (using DataUtilities.GetUtf8String(bytes, true) ), and to optionally extract important header fields, such as From, To, Date, and Subject, from the message’s text using the ExtractHeader method. Even so, though, any message for which this constructor throws a MessageDataException ought to be treated with suspicion.

Parameters:

Exceptions:

### Message Constructor

public Message(
    System.IO.Stream stream);

Initializes a new instance of the PeterO.Mail.Message class. Reads from the given Stream object to initialize the email message.

Remarks:This constructor parses an email message, and extracts its header fields and body, and throws a MessageDataException if the message is malformed. However, even if a MessageDataException is thrown, it can still be possible to display the message, especially because most email malformations seen in practice are benign in nature (such as the use of very long lines in the message). One way an application can handle the exception is to read all the bytes from the stream, to display the message, or part of it, as raw text (using DataUtilities.GetUtf8String(bytes, true) ), and to optionally extract important header fields, such as From, To, Date, and Subject, from the message’s text using the ExtractHeader method. Even so, though, any message for which this constructor throws a MessageDataException ought to be treated with suspicion.

Parameters:

Exceptions:

### Message Constructor

public Message();

Initializes a new instance of the PeterO.Mail.Message class. The message will be plain text and have an artificial From address.

### BccAddresses

public System.Collections.Generic.IList BccAddresses { get; }

Deprecated. Use GetAddresses(“Bcc”) instead.

Gets a list of addresses found in the BCC header field or fields.

Returns:

A list of addresses found in the BCC header field or fields.

### BodyString

public string BodyString { get; }

Deprecated. Use GetBodyString() instead.

Gets the body of this message as a text string. See the GetBodyString() method.

Returns:

The body of this message as a text string.

Exceptions:

### CCAddresses

public System.Collections.Generic.IList CCAddresses { get; }

Deprecated. Use GetAddresses(“Cc”) instead.

Gets a list of addresses found in the CC header field or fields.

Returns:

A list of addresses found in the CC header field or fields.

### ContentDisposition

public PeterO.Mail.ContentDisposition ContentDisposition { get; set; }

Gets or sets this message’s content disposition. The content disposition specifies how a user agent should display or otherwise handle this message. Can be set to null. If set to a disposition or to null, updates the Content-Disposition header field as appropriate. (There is no default content disposition if this value is null, and disposition types unrecognized by the application should be treated as “attachment”; see RFC 2183 sec. 2.8.).

Returns:

This message’s content disposition, or null if none is specified.

### ContentType

public PeterO.Mail.MediaType ContentType { get; set; }

Gets or sets this message’s media type. When getting, the media type may differ in certain cases from the value of the Content-Type header field, if any, and may have a value even if the Content-Type header field is absent from this message. If set to a media type, updates the Content-Type header field as appropriate. Cannot be set to null.

Returns:

This message’s media type.

Exceptions:

### FileName

public string FileName { get; }

Gets a file name suggested by this message for saving the message’s body to a file. For more information on the algorithm, see ContentDisposition.MakeFilename.

This method generates a file name based on the filename parameter of the Content-Disposition header field, if it exists, or on the name parameter of the Content-Type header field, otherwise.

Returns:

A suggested name for the file. Returns the empty string if there is no filename suggested by the content type or content disposition, or if that filename is an empty string.

### FromAddresses

public System.Collections.Generic.IList FromAddresses { get; }

Deprecated. Use GetAddresses(“From”) instead.

Gets a list of addresses found in the From header field or fields.

Returns:

A list of addresses found in the From header field or fields.

### HeaderFields

public System.Collections.Generic.IList HeaderFields { get; }

Gets a snapshot of the header fields of this message, in the order in which they appear in the message. For each item in the list, the key is the header field’s name (where any basic upper-case letters, U+0041 to U+005A, are converted to basic lower-case letters) and the value is the header field’s value.

Returns:

A snapshot of the header fields of this message.

### Parts

public System.Collections.Generic.IList Parts { get; }

Gets a list of all the parts of this message. This list is editable. This will only be used if the message is a multipart message.

Returns:

A list of all the parts of this message. This list is editable. This will only be used if the message is a multipart message.

### Subject

public string Subject { get; set; }

Gets or sets this message’s subject. The subject’s value is found as though GetHeader(“subject”) were called.

Returns:

This message’s subject, or null if there is none.

### ToAddresses

public System.Collections.Generic.IList ToAddresses { get; }

Deprecated. Use GetAddresses(“To”) instead.

Gets a list of addresses found in the To header field or fields.

Returns:

A list of addresses found in the To header field or fields.

### AddAttachment

public PeterO.Mail.Message AddAttachment(
    PeterO.Mail.MediaType mediaType);

Adds an attachment with an empty body and with the given media type to this message. Before the new attachment is added, if this message isn’t already a multipart message, it becomes a “multipart/mixed” message with the current body converted to an inline body part.

Parameters:

Return Value:

A Message object for the generated attachment.

### AddAttachment

public PeterO.Mail.Message AddAttachment(
    System.IO.Stream inputStream,
    PeterO.Mail.MediaType mediaType);

Adds an attachment to this message in the form of data from the given readable stream, and with the given media type. Before the new attachment is added, if this message isn’t already a multipart message, it becomes a “multipart/mixed” message with the current body converted to an inline body part.

The following example (written in C# for the.NET version) is an extension method that adds an attachment from a byte array to a message.

public static Message AddAttachmentFromBytes(this Message msg, byte[]
            bytes, MediaType mediaType) { using (var fs = new MemoryStream(bytes)) {
            return msg.AddAttachment(fs, mediaType); } }

.

Parameters:

Return Value:

A Message object for the generated attachment.

Exceptions:

### AddAttachment

public PeterO.Mail.Message AddAttachment(
    System.IO.Stream inputStream,
    PeterO.Mail.MediaType mediaType,
    string filename);

Adds an attachment to this message in the form of data from the given readable stream, and with the given media type and file name. Before the new attachment is added, if this message isn’t already a multipart message, it becomes a “multipart/mixed” message with the current body converted to an inline body part.

Parameters:

Return Value:

A Message object for the generated attachment.

Exceptions:

### AddAttachment

public PeterO.Mail.Message AddAttachment(
    System.IO.Stream inputStream,
    string filename);

Adds an attachment to this message in the form of data from the given readable stream, and with the given file name. Before the new attachment is added, if this message isn’t already a multipart message, it becomes a “multipart/mixed” message with the current body converted to an inline body part.

Parameters:

Return Value:

A Message object for the generated attachment.

Exceptions:

### AddHeader

public PeterO.Mail.Message AddHeader(
    string name,
    string value);

Adds a header field to the end of the message’s header. This method updates the ContentType and ContentDisposition properties if those header fields have been modified by this method.

Parameters:

Return Value:

This instance.

Exceptions:

### AddHeader

public PeterO.Mail.Message AddHeader(
    System.Collections.Generic.KeyValuePair header);

Adds a header field to the end of the message’s header. This method updates the ContentType and ContentDisposition properties if those header fields have been modified by this method.

Parameters:

Return Value:

This instance.

Exceptions:

### AddInline

public PeterO.Mail.Message AddInline(
    PeterO.Mail.MediaType mediaType);

Adds an inline body part with an empty body and with the given media type to this message. Before the new body part is added, if this message isn’t already a multipart message, it becomes a “multipart/mixed” message with the current body converted to an inline body part.

Parameters:

Return Value:

A Message object for the generated body part.

### AddInline

public PeterO.Mail.Message AddInline(
    System.IO.Stream inputStream,
    PeterO.Mail.MediaType mediaType);

Adds an inline body part to this message in the form of data from the given readable stream, and with the given media type. Before the new body part is added, if this message isn’t already a multipart message, it becomes a “multipart/mixed” message with the current body converted to an inline body part.

The following example (written in C# for the.NET version) is an extension method that adds an inline body part from a byte array to a message.

public static Message AddInlineFromBytes(this Message msg, byte[]
            bytes,
            MediaType mediaType) { using (MemoryStream fs = new MemoryStream(bytes))
            { return msg.AddInline(fs, mediaType); } }

.

Parameters:

Return Value:

A Message object for the generated body part.

Exceptions:

### AddInline

public PeterO.Mail.Message AddInline(
    System.IO.Stream inputStream,
    PeterO.Mail.MediaType mediaType,
    string filename);

Adds an inline body part to this message in the form of data from the given readable stream, and with the given media type and file name. Before the new body part is added, if this message isn’t already a multipart message, it becomes a “multipart/mixed” message with the current body converted to an inline body part.

Parameters:

Return Value:

A Message object for the generated body part.

Exceptions:

### AddInline

public PeterO.Mail.Message AddInline(
    System.IO.Stream inputStream,
    string filename);

Adds an inline body part to this message in the form of data from the given readable stream, and with the given file name. Before the new body part is added, if this message isn’t already a multipart message, it becomes a “multipart/mixed” message with the current body converted to an inline body part.

Parameters:

Return Value:

A Message object for the generated body part.

Exceptions:

### ClearHeaders

public PeterO.Mail.Message ClearHeaders();

Deletes all header fields in this message. Also clears this message’s content disposition and resets its content type to MediaType.TextPlainAscii.

Return Value:

This object.

### DecodeHeaderValue

public static string DecodeHeaderValue(
    string name,
    string value);

Decodes RFC 2047 encoded words from the given header field value and returns a string with those words decoded. For an example of encoded words, see the constructor for PeterO.Mail.NamedAddress.

Parameters:

Return Value:

The header field value with valid encoded words decoded.

Exceptions:

### ExtractHeader

public static string ExtractHeader(
    byte[] bytes,
    string headerFieldName);

Extracts the value of a header field from a byte array representing an email message. The return value is intended for display purposes, not for further processing, and this method is intended to be used as an error handling tool for email messages that are slightly malformed. (Note that malformed email messages ought to be treated with greater suspicion than well-formed email messages.).

Parameters:

Return Value:

The value of the first instance of the header field with the given name. Leading space and/or tab bytes (0x20 and/or 0x09) and CR/LF (0x0d/0x0a) pairs will be removed from the header field value, and the value is treated as encoded in UTF-8 (an 8-bit encoding form of the Unicode Standard) where illegally encoded UTF-8 is replaced as appropriate with replacement characters (U+FFFD). Returns null if bytes is null, if headerFieldName is null, is more than 997 characters long, or has a character less than U+0021 or greater than U+007E in the Unicode Standard, if a header field with that name does not exist, or if a body (even an empty one) does not follow the header fields.

### FromMailtoUri

public static PeterO.Mail.Message FromMailtoUri(
    string uri);

Creates a message object from a MailTo URI (uniform resource identifier). The MailTo URI can contain key-value pairs that follow a question-mark, as in the following example: “mailto:me@example.com?subject=A%20Subject”. In this example, “subject” is the subject of the email address. Only certain keys are supported, namely, “to”, “cc”, “bcc”, “subject”, “in-reply-to”, “comments”, “keywords”, and “body”. The first seven are header field names that will be used to set the returned message’s corresponding header fields. The last, “body”, sets the body of the message to the given text. Keys other than these eight will be ignored. (Keys are compared using a basic case-sensitive comparison, in which two strings are equal if they match after converting the basic upper-case letters A to Z (U+0041 to U+005A) in both strings to basic lower-case letters.) The same key (matched using a basic case-insensitive comparison) can appear more than once; for “subject”, “cc”, “bcc”, and “in-reply-to”, the last value with the given key is used; for “to”, all header field values as well as the path are combined to a single To header field; for “keywords” and “comments”, each value adds another header field of the given key; and for “body”, the last value with that key is used as the body.

Parameters:

Return Value:

A Message object created from the given MailTo URI. Returs null if uri is null, is syntactically invalid, or is not a MailTo URI.

### FromMailtoUri

public static PeterO.Mail.Message FromMailtoUri(
    System.Uri uri);

Creates a message object from a MailTo URI (uniform resource identifier) in the form of a URI object. For more information, see FromMailtoUri(string).

Parameters:

Return Value:

A Message object created from the given MailTo URI. Returs null if uri is null, is syntactically invalid, or is not a MailTo URI.

Exceptions:

### FromMailtoUrl

public static PeterO.Mail.Message FromMailtoUrl(
    string url);

Deprecated. Renamed to FromMailtoUri.

Creates a message object from a MailTo URI (uniform resource identifier). For more information, see FromMailtoUri(string).

Parameters:

Return Value:

A Message object created from the given MailTo URI. Returs null if url is null, is syntactically invalid, or is not a MailTo URI.

### Generate

public string Generate();

Generates this message’s data in text form. The generated message will have only Basic Latin code points (U+0000 to U+007F), and the transfer encoding will always be 7bit, quoted-printable, or base64 (the declared transfer encoding for this message will be ignored).

The following applies to the following header fields: From, To, Cc, Bcc, Reply-To, Sender, Resent-To, Resent-From, Resent-Cc, Resent-Bcc, and Resent-Sender. If the header field exists, but has an invalid syntax, has no addresses, or appears more than once, this method will combine the addresses into one header field if possible (in the case of all fields given other than From and Sender), and otherwise generate a synthetic header field with the display-name set to the contents of all of the header fields with the same name, and the address set to me@[header-name]-address.invalid as the address (a .invalid address is a reserved address that can never belong to anyone). (An exception is that the Resent-* header fields may appear more than once.) The generated message should always have a From header field.

If a Date and/or Message-ID header field doesn’t exist, a field with that name will be generated (using the current local time for the Date field).

When encoding the message’s body, if the message has a text content type (“text/*”), the line breaks are a CR byte (carriage return, 0x0d) followed by an LF byte (line feed, 0x0a), CR alone, or LF alone. If the message has any other content type, only CR followed by LF is considered a line break.

Return Value:

The generated message.

Exceptions:

### GenerateBytes

public byte[] GenerateBytes();

Generates this message’s data as a byte array, using the same algorithm as the Generate method.

Return Value:

The generated message as a byte array.

### GetAddresses

public System.Collections.Generic.IList GetAddresses(
    string headerName);

Gets a list of addresses contained in the header fields with the given name in this message.

Parameters:

Return Value:

A list of addresses, in the order in which they appear in this message’s header fields of the given name.

Exceptions:

### GetAttachments

public System.Collections.Generic.IList GetAttachments();

Gets a list of descendant body parts of this message that are considered attachments. An attachment is a body part or descendant body part that has a content disposition with a type other than inline. This message itself is not included in the list even if it’s an attachment as just defined.

Return Value:

A list of descendant body parts of this message that are considered attachments.

### GetBody

public byte[] GetBody();

Gets the byte array for this message’s body. This method doesn’ t make a copy of that byte array.

Return Value:

A byte array.

### GetBodyMessage

public PeterO.Mail.Message GetBodyMessage();

Returns the mail message contained in this message’s body.

Return Value:

A message object if this object’s content type is “message/rfc822”, “message/news”, or “message/global”, or null otherwise.

### GetBodyString

public string GetBodyString();

Gets the body of this message as a text string. If this message’s media type is “multipart/alternative”, returns the result of this method for the last supported body part. For any other “multipart” media type, returns the result of this method for the first body part for which this method returns a text string.

Return Value:

The body of this message as a text string.

Exceptions:

### GetDate

public int[] GetDate();

Gets the date and time extracted from this message’s Date header field (the value of which is found as though GetHeader(“date”) were called). See MailDateTime.ParseDateString(string, bool) for more information on the format of the date-time array returned by this method.

Return Value:

An array of 32-bit unsigned integers.

### GetFormattedBodyString

public string GetFormattedBodyString();

Gets a Hypertext Markup Language (HTML) rendering of this message’s text body. This method currently supports any message for which GetBodyString() outputs a text string and treats the following media types specially: text/plain with format=flowed , text/enriched, text/markdown (original Markdown).

REMARK: The Markdown implementation currently supports all features of original Markdown, except that the implementation:

Return Value:

An HTML rendering of this message’s text.

Exceptions:

### GetHeader

public string GetHeader(
    string name);

Gets the first instance of the header field with the specified name, using a basic case-insensitive comparison. (Two strings are equal in such a comparison, if they match after converting the basic upper-case letters A to Z (U+0041 to U+005A) in both strings to basic lower-case letters.).

Parameters:

Return Value:

The value of the first header field with that name, or null if there is none.

Exceptions:

### GetHeader

public System.Collections.Generic.KeyValuePair GetHeader(
    int index);

Gets the name and value of a header field by index.

Parameters:

Return Value:

A key/value pair. The key is the name of the header field, such as “From” or “Content-ID”. The value is the header field’s value.

Exceptions:

### GetHeaderArray

public string[] GetHeaderArray(
    string name);

Gets an array with the values of all header fields with the specified name, using a basic case-insensitive comparison. (Two strings are equal in such a comparison, if they match after converting the basic upper-case letters A to Z (U+0041 to U+005A) in both strings to basic lower-case letters.).

Parameters:

Return Value:

An array containing the values of all header fields with the given name, in the order they appear in the message. The array will be empty if no header field has that name.

Exceptions:

### MakeMultilingualMessage

public static PeterO.Mail.Message MakeMultilingualMessage(
    System.Collections.Generic.IList messages,
    System.Collections.Generic.IList languages);

Generates a multilingual message (see RFC 8255) from a list of messages and a list of language strings.

Parameters:

Return Value:

A Message object with the content type “multipart/multilingual” . It will begin with an explanatory body part and be followed by the messages given in the messages parameter in the order given.

Exceptions:

### NewBodyPart

public static PeterO.Mail.Message NewBodyPart();

Creates a message object with no header fields.

Return Value:

A message object with no header fields.

### RemoveHeader

public PeterO.Mail.Message RemoveHeader(
    int index);

Removes a header field by index. This method updates the ContentType and ContentDisposition properties if those header fields have been modified by this method.

Parameters:

Return Value:

This instance.

Exceptions:

### RemoveHeader

public PeterO.Mail.Message RemoveHeader(
    string name);

Removes all instances of the given header field from this message. If this is a multipart message, the header field is not removed from its body part headers. A basic case-insensitive comparison is used. (Two strings are equal in such a comparison, if they match after converting the basic upper-case letters A to Z (U+0041 to U+005A) in both strings to basic lower-case letters.). This method updates the ContentType and ContentDisposition properties if those header fields have been modified by this method.

Parameters:

Return Value:

This instance.

Exceptions:

### SelectLanguageMessage

public PeterO.Mail.Message SelectLanguageMessage(
    System.Collections.Generic.IList languages);

Selects a body part for a multiple-language message( multipart/multilingual ) according to the given language priority list.

Parameters:

Return Value:

The best matching body part for the given languages. If the body part has no subject, then the top-level subject is used. If this message is not a multipart/multilingual message or has fewer than two body parts, returns this object. If no body part matches the given languages, returns the last body part if its language is “zxx”, or the second body part otherwise.

Exceptions:

### SelectLanguageMessage

public PeterO.Mail.Message SelectLanguageMessage(
    System.Collections.Generic.IList languages,
    bool preferOriginals);

Selects a body part for a multiple-language message( multipart/multilingual ) according to the given language priority list and original-language preference.

Parameters:

Return Value:

The best matching body part for the given languages. If the body part has no subject, then the top-level subject is used. If this message is not a multipart/multilingual message or has fewer than two body parts, returns this object. If no body part matches the given languages, returns the last body part if its language is “zxx”, or the second body part otherwise.

Exceptions:

### SetBody

public PeterO.Mail.Message SetBody(
    byte[] bytes);

Sets the body of this message to the given byte array. This method doesn’t make a copy of that byte array.

Parameters:

Return Value:

This object.

Exceptions:

### SetCurrentDate

public PeterO.Mail.Message SetCurrentDate();

Sets this message’s Date header field to the current time as its value, with an unspecified time zone offset. This method can be used when the message is considered complete and ready to be generated, for example, using the “Generate()” method.

Return Value:

This object.

### SetDate

public PeterO.Mail.Message SetDate(
    int[] dateTime);

Sets this message’s Date header field to the given date and time.

Parameters:

Return Value:

This object.

Exceptions:

### SetHeader

public PeterO.Mail.Message SetHeader(
    int index,
    string name,
    string value);

Sets the name and value of a header field by index. This method updates the ContentType and ContentDisposition properties if those header fields have been modified by this method.

Parameters:

Return Value:

This instance.

Exceptions:

### SetHeader

public PeterO.Mail.Message SetHeader(
    int index,
    string value);

Sets the value of a header field by index without changing its name. This method updates the ContentType and ContentDisposition properties if those header fields have been modified by this method.

Parameters:

Return Value:

This instance.

Exceptions:

### SetHeader

public PeterO.Mail.Message SetHeader(
    int index,
    System.Collections.Generic.KeyValuePair header);

Sets the name and value of a header field by index. This method updates the ContentType and ContentDisposition properties if those header fields have been modified by this method.

Parameters:

Return Value:

A Message object.

Exceptions:

### SetHeader

public PeterO.Mail.Message SetHeader(
    string name,
    string value);

Sets the value of this message’s header field. If a header field with the same name exists, its value is replaced. If the header field’s name occurs more than once, only the first instance of the header field is replaced. This method updates the ContentType and ContentDisposition properties if those header fields have been modified by this method.

Parameters:

Return Value:

This instance.

Exceptions:

### SetHtmlBody

public PeterO.Mail.Message SetHtmlBody(
    string str);

Sets the body of this message to the specified string in Hypertext Markup Language (HTML) format. The character sequences CR (carriage return, “\r”, U+000D), LF (line feed, “\n”, U+000A), and CR/LF will be converted to CR/LF line breaks. Unpaired surrogate code points will be replaced with replacement characters.

Parameters:

Return Value:

This instance.

Exceptions:

### SetTextAndHtml

public PeterO.Mail.Message SetTextAndHtml(
    string text,
    string html);

Sets the body of this message to a multipart body with plain text and Hypertext Markup Language (HTML) versions of the same message. The character sequences CR (carriage return, “\r”, U+000D), LF (line feed, “\n”, U+000A), and CR/LF will be converted to CR/LF line breaks. Unpaired surrogate code points will be replaced with replacement characters.

Parameters:

Return Value:

This instance.

Exceptions:

### SetTextAndMarkdown

public PeterO.Mail.Message SetTextAndMarkdown(
    string text,
    string markdown);

Sets the body of this message to a multipart body with plain text, Markdown, and Hypertext Markup Language (HTML) versions of the same message. The character sequences CR (carriage return, “\r”, U+000D), LF (line feed, “\n”, U+000A), and CR/LF will be converted to CR/LF line breaks. Unpaired surrogate code points will be replaced with replacement characters.

REMARK: The Markdown-to-HTML implementation currently supports all features of original Markdown, except that the implementation:

Parameters:

Return Value:

This instance.

Exceptions:

### SetTextBody

public PeterO.Mail.Message SetTextBody(
    string str);

Sets the body of this message to the specified plain text string. The character sequences CR (carriage return, “\r”, U+000D), LF (line feed, “\n”, U+000A), and CR/LF will be converted to CR/LF line breaks. Unpaired surrogate code points will be replaced with replacement characters. This method changes this message’s media type to plain text.

Parameters:

Return Value:

This instance.

Exceptions:

### ToMailtoUri

public string ToMailtoUri();

Generates a MailTo URI (uniform resource identifier) corresponding to this message. The following header fields, and only these, are used to generate the URI: To, Cc, Bcc, In-Reply-To, Subject, Keywords, Comments. The message body is included in the URI only if GetBodyString() would return a non-empty string.. The To header field is included in the URI only if it has display names or group syntax.

Return Value:

A MailTo URI corresponding to this message.

### ToMailtoUrl

public string ToMailtoUrl();

Deprecated. Renamed to ToMailtoUri.

Generates a MailTo URI (uniform resource identifier) corresponding to this message. The following header fields, and only these, are used to generate the URI: To, Cc, Bcc, In-Reply-To, Subject, Keywords, Comments. The message body is included in the URI only if GetBodyString() would return a non-empty string. The To header field is included in the URI only if it has display names or group syntax.

Return Value:

A MailTo URI corresponding to this message.

Back to MailLib start page.