GemBox.Email
  • Overview
  • Examples
  • Free version
  • Support
  • Pricelist

    Show / Hide Table of Contents

    MailMessage Class

    Namespace:
    GemBox.Email
    Assembly:
    GemBox.Email.dll

    Represents an email message.

    • C#
    • VB.NET
    public sealed class MailMessage
    Public NotInheritable Class MailMessage
    Inheritance:
    System.Object
    MailMessage

    Constructors

    MailMessage()

    Initializes a new instance of the MailMessage class.

    • C#
    • VB.NET
    public MailMessage()
    Public Sub New

    MailMessage(MailAddress)

    Initializes a new instance of the MailMessage class with specified sender.

    • C#
    • VB.NET
    public MailMessage(MailAddress from)
    Public Sub New(from As MailAddress)
    Parameters
    from
    MailAddress

    The sender address.

    MailMessage(MailAddress, MailAddress[])

    Initializes a new instance of the MailMessage class with specified sender and recipient addresses.

    • C#
    • VB.NET
    public MailMessage(MailAddress from, params MailAddress[] to)
    Public Sub New(from As MailAddress, ParamArray to As MailAddress())
    Parameters
    from
    MailAddress

    The sender address.

    to
    MailAddress[]

    The recipient addresses.

    MailMessage(String)

    Initializes a new instance of the MailMessage class with specified sender.

    • C#
    • VB.NET
    public MailMessage(string from)
    Public Sub New(from As String)
    Parameters
    from
    System.String

    The sender address.

    MailMessage(String, String[])

    Initializes a new instance of the MailMessage class with specified sender and recipient addresses.

    • C#
    • VB.NET
    public MailMessage(string from, params string[] to)
    Public Sub New(from As String, ParamArray to As String())
    Parameters
    from
    System.String

    The sender address.

    to
    System.String[]

    The recipient addresses.

    Properties

    Attachments

    Gets the attachments collection.

    • C#
    • VB.NET
    public AttachmentCollection Attachments { get; }
    Public ReadOnly Property Attachments As AttachmentCollection
    Property Value
    AttachmentCollection

    The attachments collection.

    Bcc

    Gets the 'Bcc' address collection.

    • C#
    • VB.NET
    public MailAddressCollection Bcc { get; }
    Public ReadOnly Property Bcc As MailAddressCollection
    Property Value
    MailAddressCollection

    The 'Bcc' address collection.

    BodyHtml

    Gets or sets the message HTML body.

    • C#
    • VB.NET
    public string BodyHtml { get; set; }
    Public Property BodyHtml As String
    Property Value
    System.String

    The message HTML body.

    BodyText

    Gets or sets the message text body.

    • C#
    • VB.NET
    public string BodyText { get; set; }
    Public Property BodyText As String
    Property Value
    System.String

    The message text body.

    BodyTextCharset

    Gets or sets the message text body charset.

    • C#
    • VB.NET
    public Encoding BodyTextCharset { get; set; }
    Public Property BodyTextCharset As Encoding
    Property Value
    System.Text.Encoding

    The message text body charset.

    Calendars

    Gets the calendars collection. Changes made to calendars retrieved through this property will NOT be synchronized with MailMessage.

    • C#
    • VB.NET
    public CalendarCollection Calendars { get; }
    Public ReadOnly Property Calendars As CalendarCollection
    Property Value
    CalendarCollection

    The calendars collection.

    Remarks

    Calendars are currently not load from and saved to MSG file format.

    Cc

    Gets the 'Cc' address collection.

    • C#
    • VB.NET
    public MailAddressCollection Cc { get; }
    Public ReadOnly Property Cc As MailAddressCollection
    Property Value
    MailAddressCollection

    The 'Cc' address collection.

    ConversationIndex

    Gets the conversation index for this message.

    note

    Only available for .MSG files.

    • C#
    • VB.NET
    public ConversationIndex ConversationIndex { get; }
    Public ReadOnly Property ConversationIndex As ConversationIndex
    Property Value
    ConversationIndex

    Date

    Gets or sets the message date.

    • C#
    • VB.NET
    public DateTime Date { get; set; }
    Public Property Date As Date
    Property Value
    System.DateTime

    The message date.

    From

    Gets the 'From' address collection.

    • C#
    • VB.NET
    public MailAddressCollection From { get; }
    Public ReadOnly Property From As MailAddressCollection
    Property Value
    MailAddressCollection

    The 'From' address collection.

    Id

    Gets or sets the message id.

    • C#
    • VB.NET
    public string Id { get; set; }
    Public Property Id As String
    Property Value
    System.String

    The message id.

    IsSigned

    Gets a value indicating whether this MailMessage is signed.

    • C#
    • VB.NET
    public bool IsSigned { get; }
    Public ReadOnly Property IsSigned As Boolean
    Property Value
    System.Boolean
    Remarks

    Signed MailMessage are read-only, so any attempts to change the content (body or attachments) will result in an System.InvalidOperationException being thrown.
    Nonetheless, it is possible to call Unsign() to access a new, unsigned and changeable MailMessage.

    MessageSecurity

    Gets a value indicating the type of security that is applied to this MailMessage.

    • C#
    • VB.NET
    public MessageSecurityType MessageSecurity { get; }
    Public ReadOnly Property MessageSecurity As MessageSecurityType
    Property Value
    MessageSecurityType

    MimeEntity

    Gets the underlying MIME entity.

    • C#
    • VB.NET
    public Entity MimeEntity { get; }
    Public ReadOnly Property MimeEntity As Entity
    Property Value
    Entity

    The underlying MIME entity.

    Exceptions
    System.ArgumentNullException

    value

    ReplyTo

    Gets the 'Reply-To' address collection.

    • C#
    • VB.NET
    public MailAddressCollection ReplyTo { get; }
    Public ReadOnly Property ReplyTo As MailAddressCollection
    Property Value
    MailAddressCollection

    The 'Reply-To' address collection.

    RequestDeliveryReceipt

    Gets or sets if the message should be sent with a delivery receipt request

    • C#
    • VB.NET
    public bool RequestDeliveryReceipt { get; set; }
    Public Property RequestDeliveryReceipt As Boolean
    Property Value
    System.Boolean

    RequestReadReceipt

    Gets or sets if the message should be sent with a read receipt request

    • C#
    • VB.NET
    public bool RequestReadReceipt { get; set; }
    Public Property RequestReadReceipt As Boolean
    Property Value
    System.Boolean

    Sender

    Gets or sets the sender address

    • C#
    • VB.NET
    public MailAddress Sender { get; set; }
    Public Property Sender As MailAddress
    Property Value
    MailAddress

    The sender address.

    Subject

    Gets or sets the message subject.

    • C#
    • VB.NET
    public string Subject { get; set; }
    Public Property Subject As String
    Property Value
    System.String

    The message subject.

    To

    Gets the 'To' address collection.

    • C#
    • VB.NET
    public MailAddressCollection To { get; }
    Public ReadOnly Property To As MailAddressCollection
    Property Value
    MailAddressCollection

    The 'To' address collection.

    Methods

    Clone()

    Creates the copy of this MailMessage instance.

    • C#
    • VB.NET
    public MailMessage Clone()
    Public Function Clone As MailMessage
    Returns
    MailMessage

    The copy of this MailMessage instance.

    GetEmbeddedBodyHtml()

    Gets the message HTML body with embedded images replaced by inlined images (base64-encoded data URIs).

    • C#
    • VB.NET
    public string GetEmbeddedBodyHtml()
    Public Function GetEmbeddedBodyHtml As String
    Returns
    System.String

    The message HTML body with embedded images replaced by inline data URIs.

    GetSignature()

    Gets information on the signature applied to this message (if it exists) and the certificate used to create it.

    • C#
    • VB.NET
    public DigitalSignatureInfo GetSignature()
    Public Function GetSignature As DigitalSignatureInfo
    Returns
    DigitalSignatureInfo

    GetTaggedProperty(PropertyTag)

    Returns the value stored into a specific tagged property. Works only for messages loaded from MSG files.

    • C#
    • VB.NET
    public object GetTaggedProperty(PropertyTag tag)
    Public Function GetTaggedProperty(tag As PropertyTag) As Object
    Parameters
    tag
    PropertyTag

    The ID of the tag from which to retrieve the value.

    Returns
    System.Object

    An System.Object containing the value of the specified tag or null if the property was not found.

    Load(Stream, MailMessageFormat)

    Loads the message from the specified stream.

    • C#
    • VB.NET
    public static MailMessage Load(Stream stream, MailMessageFormat format)
    Public Shared Function Load(stream As Stream, format As MailMessageFormat) As MailMessage
    Parameters
    stream
    System.IO.Stream

    The stream from which the message will be loaded.

    format
    MailMessageFormat

    The message format.

    Returns
    MailMessage

    MailMessage instance.

    Exceptions
    System.ArgumentNullException

    Stream is null.

    System.ArgumentException

    Unknown message format.

    Load(String)

    Loads the message from the specified file.

    • C#
    • VB.NET
    public static MailMessage Load(string filePath)
    Public Shared Function Load(filePath As String) As MailMessage
    Parameters
    filePath
    System.String

    A relative or absolute path to the file.

    Returns
    MailMessage

    MailMessage instance.

    Exceptions
    System.ArgumentException

    File path is null or empty.

    Load(String, MailMessageFormat)

    Loads the message from the specified file.

    • C#
    • VB.NET
    public static MailMessage Load(string filePath, MailMessageFormat format)
    Public Shared Function Load(filePath As String, format As MailMessageFormat) As MailMessage
    Parameters
    filePath
    System.String

    A relative or absolute path to the file.

    format
    MailMessageFormat

    The message format.

    Returns
    MailMessage

    MailMessage instance.

    Exceptions
    System.ArgumentException

    File path is null or empty.

    Save(Stream, MailMessageFormat)

    Saves the message to a stream.

    • C#
    • VB.NET
    public void Save(Stream stream, MailMessageFormat format)
    Public Sub Save(stream As Stream, format As MailMessageFormat)
    Parameters
    stream
    System.IO.Stream

    The stream to save the message to.

    format
    MailMessageFormat

    The message format.

    Exceptions
    System.ArgumentNullException

    Stream is null.

    System.ArgumentException

    Unknown message format.

    Save(String)

    Saves the message to a file.

    • C#
    • VB.NET
    public void Save(string filePath)
    Public Sub Save(filePath As String)
    Parameters
    filePath
    System.String

    A relative or absolute path for the file where message will be saved.

    Exceptions
    System.ArgumentException

    File path is null or empty.

    Save(String, MailMessageFormat)

    Saves the message to a file.

    • C#
    • VB.NET
    public void Save(string filePath, MailMessageFormat format)
    Public Sub Save(filePath As String, format As MailMessageFormat)
    Parameters
    filePath
    System.String

    A relative or absolute path for the file where message will be saved.

    format
    MailMessageFormat

    The message format.

    Exceptions
    System.ArgumentException

    File path is null or empty.

    SetTaggedProperty(PropertyTag, Object)

    Explicitly sets the value of a tagged property. Works only for messages that will be saved to a MSG file. Items set with this method will be written when saving the message to .msg, overwriting any other properties normally set by other members, which can cause errors.
    For example, setting GemBox.Email.Msg.Properties.PropertyTag.Subject will override the subject regardless of what is on Subject.

    • C#
    • VB.NET
    public void SetTaggedProperty(PropertyTag tag, object value)
    Public Sub SetTaggedProperty(tag As PropertyTag, value As Object)
    Parameters
    tag
    PropertyTag

    The ID of the tag to set.

    value
    System.Object

    The value of the tagged property.

    Sign(DigitalSignatureOptions)

    Applies a digital signature to this MailMessage based on given DigitalSignatureOptions.

    • C#
    • VB.NET
    public void Sign(DigitalSignatureOptions options)
    Public Sub Sign(options As DigitalSignatureOptions)
    Parameters
    options
    DigitalSignatureOptions

    The DigitalSignatureOptions to be used while creating the signature.

    Remarks

    Signed MailMessage are read-only, so any attempts to change the content (body or attachments) will result in an System.InvalidOperationException being thrown.
    Nonetheless, it is possible to call Unsign() to remove it's signature and make it changeable again.

    Exceptions
    System.InvalidOperationException

    IsSigned is true.

    System.ArgumentNullException

    Certificate and CertificatePath are null.

    Unsign()

    Removes the digital signature from this MailMessage and removes it's read-only status.

    • C#
    • VB.NET
    public void Unsign()
    Public Sub Unsign
    Exceptions
    System.InvalidOperationException

    IsSigned is false.

    ValidateSignature()

    Verifies if this message's signature is valid and if the certificate used to generate it is still active.

    • C#
    • VB.NET
    public bool ValidateSignature()
    Public Function ValidateSignature As Boolean
    Returns
    System.Boolean

    If this message's signature is valid, true, if not, false.

    Remarks

    If IsSigned is false, this method will always return false.

    Examples

    How to sign and unsign an e-mail in C# and VB.NET
    How to validate a signed e-mail in C# and VB.NET
    Back to top

    Facebook • Twitter • LinkedIn

    © GemBox Ltd. — All rights reserved.