MailMessage Class
Provides properties and methods for constructing and examining a single e-mail message.
Inheritance Hierarchy
SystemObject
  MailBee.MimeMailMessage

Namespace: MailBee.Mime
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax
public class MailMessage : IDisposable

The MailMessage type exposes the following members.

Constructors
  NameDescription
Public methodMailMessage
Initializes a new instance of the MailMessage class
Top
Methods
  NameDescription
Public methodCode exampleAppendChunk
Adds a block of bytes to the source of the message.
Public methodCode exampleAppendPartialMessage
Adds the specified partial message to this message.
Public methodCode exampleClear
Removes the specified elements from the message.
Public methodCode exampleClone
Creates a copy of the message.
Public methodConvertFromSystemNetMail
Loads the message from System.Net.Mail.MailMessage object.
Public methodConvertToSystemNetMail
Exports the message to System.Net.Mail.MailMessage object.
Public methodCode exampleDeserialize(String)
Loads a message from the specified .XML file.
Public methodCode exampleDeserialize(XmlReader)
Loads a message from XML stream using the specified XmlReader object.
Public methodDeserializeAsync(String)
async/await version of Deserialize(String).
Public methodDeserializeAsync(XmlReader)
async/await version of Deserialize(XmlReader).
Public methodDispose
Removes the temporary folders and files that are associated with the mail message.
Public methodCode exampleDomainKeysSign
Signs the current e-mail message with DKIM and classic DomainKeys signatures.
Public methodCode exampleDomainKeysVerify
Verifies DKIM and classic DomainKeys signatures of the current e-mail message.
Public methodDomainKeysVerifyAsync
Public methodCode exampleEncodeAllHeaders
Encodes all message headers into the specified encoding.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Finalizes the instance of MailMessage object.
(Overrides ObjectFinalize.)
Public methodCode exampleForwardAsAttachment
Forwards a mail message as attached .EML file.
Public methodCode exampleGetAllRecipients
Gets the EmailAddressCollection object containing the e-mail addresses of all message recipients.
Public methodStatic memberCode exampleGetEncodedHeaderValue
Encodes the value of the specified header.
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodCode exampleGetHtmlAndRelatedFilesInMemory
Gets HTML body with references to all inline attachments being replaced with user-defined indexed paths.
Public methodCode exampleGetHtmlAndSaveRelatedFiles
Extracts the HTML body of the message, saves the attached inline pictures and other related files to disk, and return the modified HTML body.
Public methodCode exampleGetHtmlAndSaveRelatedFiles(String, VirtualMappingType, MessageFolderBehavior)
Prepares the HTML body of the message for displaying in a web application: saves all embedded objects to a temporary location, replaces their Content-ID's with their virtual paths in the temporary location, and returns the modified HTML body as a string.
Public methodGetHtmlAndSaveRelatedFilesAsync
Public methodGetHtmlAndSaveRelatedFilesAsync(String, VirtualMappingType, MessageFolderBehavior)
Public methodCode exampleGetHtmlWithBase64EncodedRelatedFiles
Gets the HTML body with all related files being embedded directly in the HTML body as base64 chunks.
Public methodCode exampleGetMessageRawData
Gets the source of the message as a byte array.
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodCode exampleImportRelatedFiles
Adds all the related files (referenced in HTML part of the message) as inline attachments.
Public methodImportRelatedFilesAsync
Public methodCode exampleIsBodyAvail
Indicates if the body of the specified format is present in the message.
Public methodCode exampleLoadBodyText(String, MessageBodyType)
Loads the contents of the specified file into HTML or plain-text body of the message.
Public methodCode exampleLoadBodyText(String, MessageBodyType, Encoding, ImportBodyOptions)
Loads the contents of the specified file or web page into HTML or plain-text body of the message, also attaching related objects such as inline images if necessary.
Public methodLoadBodyTextAsync(String, MessageBodyType)
async/await version of LoadBodyText(String, MessageBodyType).
Public methodLoadBodyTextAsync(String, MessageBodyType, Encoding, ImportBodyOptions)
Public methodCode exampleLoadMessage(Byte)
Loads the message from a byte array.
Public methodCode exampleLoadMessage(Stream)
Loads the message from a stream.
Public methodCode exampleLoadMessage(String)
Loads the message from the specified file.
Public methodLoadMessageAsync(Stream)
async/await version of LoadMessage(Stream).
Public methodLoadMessageAsync(String)
async/await version of LoadMessage(String).
Public methodCode exampleMakePlainBodyFromHtmlBody
Creates a plain text body from the existing HTML body of the message.
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodCode exampleReset
Resets all the properties of the MailMessage object to the default values.
Public methodCode exampleSaveHtmlAndRelatedFiles
Saves the HTML body of the message and all inline pictures and other inline objects to disk.
Public methodSaveHtmlAndRelatedFilesAsync
async/await version of SaveHtmlAndRelatedFiles(String).
Public methodCode exampleSaveMessage(Stream)
Saves a message into the specified stream.
Public methodCode exampleSaveMessage(String)
Saves a message into the specified file.
Public methodSaveMessageAsync(Stream)
async/await version of SaveMessage(Stream).
Public methodSaveMessageAsync(String)
async/await version of SaveMessage(String).
Public methodCode exampleSerialize(String)
Saves the message into the specified .XML file.
Public methodCode exampleSerialize(XmlWriter)
Saves the message into XML stream using the specified XmlWriter object.
Public methodSerializeAsync(String)
async/await version of Serialize(String).
Public methodSerializeAsync(XmlWriter)
async/await version of Serialize(XmlWriter).
Public methodCode exampleSetDateFromString
Sets the date of the message creation as a string.
Public methodCode exampleSetUniqueMessageID
Sets a new unique value of Message-ID header and returns it.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Properties
  NameDescription
Public propertyCode exampleAttachments
Gets the AttachmentCollection object containing the attachments of the mail message.
Public propertyCode exampleBcc
Gets or sets the list of blind carbon copy (BCC) recipients of the message.
Public propertyCode exampleBodyHtmlText
Gets or sets the HTML body of the message.
Public propertyCode exampleBodyParts
Gets all the text bodies of the message.
Public propertyCode exampleBodyPlainText
Gets or sets the plain-text body of the message.
Public propertyCode exampleBuilder
Gets or sets the options which affect how the mail message is built by MailBee.
Public propertyCode exampleCc
Gets or sets the list of carbon copy (CC) recipients of the message.
Public propertyCode exampleCharset
Gets or sets the name of the charset which was used to compose the message.
Public propertyCode exampleConfirmRead
Gets or sets the e-mail address of an entity which should receive the read confirmation message.
Public propertyCode exampleConfirmReceipt
Gets or sets the e-mail address of an entity which should receive the delivery confirmation message (when the message gets into mailbox of the server).
Public propertyCode exampleContentType
Gets the content type of the message.
Public propertyCode exampleDate
Gets or sets the date and the time when the mail message was composed.
Public propertyCode exampleDateReceived
Gets the date and the time when the message was received by the server.
Public propertyDateSent
Gets or sets the date and the time when the mail message was sent.
Public propertyFilename
Gets the filename of the file this message was loaded from.
Public propertyCode exampleFrom
Gets or sets the e-mail address of the message sender.
Public propertyCode exampleHasAttachments
Indicates if the message has any attachments.
Public propertyCode exampleHeaders
Gets the collection of the message headers.
Public propertyCode exampleImportance
Gets or sets the importance of the message.
Public propertyIndexOnServer
Gets the index of the mail message stored on the mail server.
Public propertyCode exampleIsEncrypted
Indicates if the message is encrypted.
Public propertyCode exampleIsEntire
Indicates if the message was received completely.
Public propertyCode exampleIsSigned
Indicates if the message has a digital signature.
Public propertyCode exampleLastResult
Gets the code of the last occurred error.
Public propertyCode exampleMailTransferEncodingHtml
Gets or sets the transfer encoding of the HTML body of the message.
Public propertyCode exampleMailTransferEncodingPlain
Gets or sets the transfer encoding of the plain-text body of the message.
Public propertyMdnReportType
Gets or sets report-type value for Message Disposition Notification (MDN) messages.
Public propertyCode exampleMerge
Gets the MailMerge object which can be used to perform mail merge using the current e-mail message as a template.
Public propertyCode exampleMessageID
Gets or sets the Message-ID header of the message.
Public propertyCode exampleMimePartTree
Gets the root MIME part of the message.
Public propertyCode exampleOrganization
Gets or sets the name of organization to which the sender of the message belongs.
Public propertyCode exampleParser
Gets or sets the options which affect how the MailMessage object is parsed.
Public propertyCode examplePartCount
Gets the number of parts of the composite message which is split into the several smaller mail messages.
Public propertyCode examplePartIndex
Gets the index of the current part in the sequence of parts of a composite message.
Public propertyCode examplePriority
Gets or sets the priority of the message.
Public propertyCode exampleRawHeader
Gets the message header section exactly as it is contained in the message.
Public propertyCode exampleReferences
Gets or sets the references of the message.
Public propertyCode exampleReplyTo
Gets or sets the list of the e-mail addresses where to send a reply to this message.
Public propertyCode exampleReturnPath
Gets the value of Return-Path header.
Public propertySender
Gets or sets the value of Sender header.
Public propertyCode exampleSensitivity
Gets or sets the sensitivity of the message.
Public propertyCode exampleSize
Gets the size of the message in bytes.
Public propertyCode exampleSizeOnServer
Gets the actual message size on the mail server.
Public propertyCode exampleSubject
Gets or sets the subject of the message.
Public propertyCode exampleThrowExceptions
Gets or sets whether the MailMessage object will throw exceptions on errors.
Public propertyCode exampleTimeStamps
Gets the collection of which represents the trace route of the message.
Public propertyCode exampleTo
Gets or sets the e-mail addresses of the primary recipients of the mail message.
Public propertyCode exampleUidOnServer
Gets Unique-ID (UID) of the message in the mailbox on the server.
Public propertyCode exampleVersion
Gets the current version of MailBee.NET Objects.
Public propertyCode exampleXMailer
Gets or sets the details about the software which was used to create the message.
Top
Remarks
MailMessage is a standard container for e-mail messages.

Moreover MailMessage

  • Gives access to all parts of the message such as headers, bodies, attachments, time stamps (Received headers), etc
  • Has comprehensive facilities for message modification (such as HTML to plain-text conversion, preparing HTML with embedded pictures for dispaying, etc)
  • Offers the full support of international charsets and e-mail addresses (IDN domains)
  • Supports mail merge capabilitites, DomainKeys and DKIM, XML serialization, and much more
Examples
This sample composes a mail message and saves it to disk using two methods: as .EML file and as .XML file.
using System.Text;
using MailBee;
using MailBee.Mime;

class Sample
{
    static void Main(string[] args)
    {
        MailMessage msg = new MailMessage();

        // Set the recipient e-mail from string.
        msg.To.AddFromString("some_user@domain.com");

        // Add more recipient e-mail's along with recipient
        // names and corresponding remarks.
        msg.To.Add("user1@domain.com", "User 1", "Remark");
        msg.To.Add("user2@domain.com", "User 2", "");

        // Set the sender e-mail from string.
        msg.From.Email = "jdoe@domain.com";

        // Set the friendly name of the message sender.
        msg.From.DisplayName = "John Doe";

        // Set the subject of the message.
        msg.Subject = "Hello";

        // Set Carbon Copy (CC) recipient e-mail along with
        // corresponding name and remarks.
        msg.Cc.Add("user3@domain.com", "User 3", "Remark");

        // Set the plain-formatted body of the message.
        msg.BodyPlainText = "Hello, World!";

        // Set the HTML-formatted body of the message.
        msg.BodyHtmlText = @"Hello, <b>World</b>!<br>
            <IMG alt="""" hspace=0 src=""cid:12345"" align=baseline border=0><br>
            <IMG alt="""" hspace=0 src=""cid:67891"" align=baseline border=0>";

        // Specify the charset of the message.
        msg.Charset = "utf-8";

        // Set the Quoted-Printable encoding for plain-formatted body.
        msg.MailTransferEncodingPlain = MailTransferEncoding.QuotedPrintable;

        // Set the Quoted-Printable encoding for HTML-formatted body.
        msg.MailTransferEncodingHtml = MailTransferEncoding.QuotedPrintable;

        // Add three different attachments to the message.
        msg.Attachments.Add(@"C:\Docs\new.gif", "1.gif", "12345");
        msg.Attachments.Add(@"C:\Docs\old.gif", "2.gif", "67891");
        msg.Attachments.Add(@"C:\Docs\2.jpg", "2.jpg");

        // Encode all message headers into Base64 encoding.
        msg.EncodeAllHeaders(Encoding.Default, HeaderEncodingOptions.Base64);

        // Set the unique message identifier.
        msg.SetUniqueMessageID("");

        // Save message to the disk as .eml file.
        msg.SaveMessage(@"C:\Temp\TestMail.eml");

        // Serialize message into .xml file on the disk.
        msg.Serialize(@"C:\Temp\TestMail.xml");
    }
}
See Also