MailMessage Class
Represents an email message.
- Inheritance:
- System.ObjectMailMessage
Constructors
MailMessage()
Initializes a new instance of the MailMessage class.
MailMessage(MailAddress)
Initializes a new instance of the MailMessage class with specified sender.
Parameters
from
- MailAddress
The sender address.
MailMessage(MailAddress, MailAddress[])
Initializes a new instance of the MailMessage class with specified sender and recipient addresses.
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.
Parameters
from
- System.String
The sender address.
MailMessage(String, String[])
Initializes a new instance of the MailMessage class with specified sender and recipient addresses.
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.
public AttachmentCollection Attachments { get; }
Public ReadOnly Property Attachments As AttachmentCollection
Property Value
The attachments collection.
Bcc
Gets the 'Bcc' address collection.
public MailAddressCollection Bcc { get; }
Public ReadOnly Property Bcc As MailAddressCollection
Property Value
The 'Bcc' address collection.
BodyHtml
Gets or sets the message HTML body.
Property Value
- System.String
The message HTML body.
BodyText
Gets or sets the message text body.
Property Value
- System.String
The message text body.
BodyTextCharset
Gets or sets the message text body charset.
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.
public CalendarCollection Calendars { get; }
Public ReadOnly Property Calendars As CalendarCollection
Property Value
The calendars collection.
Remarks
Calendars are currently not load from and saved to MSG file format.
Cc
Gets the 'Cc' address collection.
public MailAddressCollection Cc { get; }
Public ReadOnly Property Cc As MailAddressCollection
Property Value
The 'Cc' address collection.
ConversationIndex
Gets the conversation index for this message.
note
Only available for .MSG files.
public ConversationIndex ConversationIndex { get; }
Public ReadOnly Property ConversationIndex As ConversationIndex
Property Value
Date
Gets or sets the message date.
Property Value
- System.DateTime
The message date.
From
Gets the 'From' address collection.
public MailAddressCollection From { get; }
Public ReadOnly Property From As MailAddressCollection
Property Value
The 'From' address collection.
Id
Gets or sets the message id.
Property Value
- System.String
The message id.
IsSigned
Gets a value indicating whether this MailMessage is signed.
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.
public MessageSecurityType MessageSecurity { get; }
Public ReadOnly Property MessageSecurity As MessageSecurityType
Property Value
MimeEntity
Gets the underlying MIME entity.
Property Value
The underlying MIME entity.
Exceptions
- System.ArgumentNullException
value
ReplyTo
Gets the 'Reply-To' address collection.
public MailAddressCollection ReplyTo { get; }
Public ReadOnly Property ReplyTo As MailAddressCollection
Property Value
The 'Reply-To' address collection.
Sender
Gets or sets the sender address
Property Value
The sender address.
Subject
Gets or sets the message subject.
Property Value
- System.String
The message subject.
To
Gets the 'To' address collection.
public MailAddressCollection To { get; }
Public ReadOnly Property To As MailAddressCollection
Property Value
The 'To' address collection.
Methods
Clone()
Creates the copy of this MailMessage instance.
Returns
The copy of this MailMessage instance.
GetEmbeddedBodyHtml()
Gets the message HTML body with embedded images replaced by inlined images (base64-encoded data URIs).
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.
public DigitalSignatureInfo GetSignature()
Public Function GetSignature As DigitalSignatureInfo
Returns
GetTaggedProperty(PropertyTag)
Returns the value stored into a specific tagged property. Works only for messages loaded from MSG files.
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.
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 instance.
Exceptions
- System.ArgumentNullException
Stream is null.
- System.ArgumentException
Unknown message format.
Load(String)
Loads the message from the specified file.
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 instance.
Exceptions
- System.ArgumentException
File path is null or empty.
Load(String, MailMessageFormat)
Loads the message from the specified file.
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 instance.
Exceptions
- System.ArgumentException
File path is null or empty.
Save(Stream, MailMessageFormat)
Saves the message to a stream.
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.
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.
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.
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.
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.
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.
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.