MailBee.NET Objects 3.1

MailMessage Class

Provides properties and methods for constructing and examining a single e-mail message.

For a list of all members of this type, see MailMessage Members.

System.Object
   MailBee.Mime.MailMessage

public class MailMessage : IDisposable

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Remarks

MailMessage is a standard container for e-mail messages.

Moreover MailMessage

Example

This sample composes a mail message and saves it to disk using two methods: as .EML file and as .XML file.

[C#]
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");
    }
}
[Visual Basic]
Imports System.Text
Imports MailBee
Imports MailBee.Mime

Module Sample
    Sub Main(ByVal args As String())
        Dim msg As 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 disk as .eml file.
        msg.SaveMessage("C:\Temp\TestMail.eml")

        ' Serialize message into .xml file on disk.
        msg.Serialize("C:\Temp\TestMail.xml")
    End sub
End Module

Requirements

Namespace: MailBee.Mime

Assembly: MailBee.NET (in MailBee.NET.dll)

See Also

MailMessage Members | MailBee.Mime Namespace | Attachment