public class MailMessage extends Object implements com.aspose.ms.System.IDisposable, IPreferredTextEncodingProvider, IMessage, com.aspose.ms.System.Collections.Generic.IGenericEnumerable<MailMessage>
Represents an e-mail message. It allows to access message properties, ex. subject, body, sender and recipients addreses, etc. Also it can be sent and delivered by means of supported mail protocols.
Constructor and Description |
---|
MailMessage()
Initializes a new instance of the
MailMessage class |
MailMessage(boolean increaseCredit)
Initializes a new instance of the
MailMessage class |
MailMessage(MailAddress from,
MailAddress to)
Initializes a new instance of the
MailMessage class |
MailMessage(String from,
String to)
Initializes a new instance of the
MailMessage class |
MailMessage(String from,
String to,
String subject,
String body)
Initializes a new instance of the
MailMessage class |
Modifier and Type | Method and Description |
---|---|
void |
addAlternateView(AlternateView view)
Add an alternate view to message
|
void |
addAttachment(Attachment attachment)
Add an attachment to message
|
MailMessage |
attachSignature(byte[] certificateRawData,
String certificatePassword)
Creates a signed message.
|
BounceResult |
checkBounced()
Checks whether this message can be treated as a bounce message.
|
String[] |
checkSignature()
Checking signature exsisting MailMessage.
|
static boolean |
checkSignature(InputStream stream)
Checks the signature of the specified eml message.
|
static boolean |
checkSignature(String fileName)
Checks the signature of the specified eml file.
|
MailMessage |
createReadReceipt(String from,
String bodyText)
Creates the read receipt.
|
MailMessage |
decrypt()
Decrypts this message
|
MailMessage |
decrypt(byte[] certificateRawData,
String certificatePassword)
Decrypts this message
|
MailMessage |
deepClone()
Clones this instance
|
void |
dispose()
Releases all resources used by the MailMessage
|
protected void |
dispose(boolean disposing)
Releases unmanaged and - optionally - managed resources
|
MailMessage |
dKIMSign(com.aspose.ms.System.Security.Cryptography.RSACryptoServiceProvider rsa,
DKIMSignatureInfo signatureInfo)
Signs this message using DKIM (DomainKeys Identified Mail) signature.
|
MailMessage |
encrypt(byte[] certificateRawData,
String certificatePassword)
Encrypts this message
|
boolean |
equals(Object obj)
Determines whether the specified Object is equal to the current Object.
|
AlternateViewCollection |
getAlternateViews()
Gets the collection of alternate views of message
|
AttachmentCollection |
getAttachments()
Gets the collection of attachments of message
|
MailAddressCollection |
getBcc()
Gets or sets the address collection
that contains the BCC recipients of message
|
String |
getBody()
Gets or sets the plain text representation of message's body.
|
Charset |
getBodyEncoding()
Gets or sets encoding of body
|
int |
getBodyType()
Gets the type of the body.
|
com.aspose.ms.System.Collections.Generic.IGenericCollection<MailAddress> |
getCc()
Gets CC recipients
|
MailAddressCollection |
getCC()
Gets or sets the address collection
that contains the CC recipients
|
Date |
getDate()
Gets or sets the date of message
|
int |
getDeliveryNotificationOptions()
Gets or sets the delivery notifications
|
MailAddress |
getFrom()
Gets or sets the from address
|
HeaderCollection |
getHeaders()
Gets headers collection of message
|
String |
getHtmlBody()
Gets or sets html body
|
String |
getHtmlBodyText()
Gets the message htmlbody as plain text.
|
String |
getHtmlBodyText(boolean showUrl)
Gets the message htmlbody as plain text.
|
String |
getHtmlBodyText(HyperlinkRenderingCallback hyperlinkRenderingCallback)
Gets the message htmlbody as plain text.
|
LinkedResourceCollection |
getLinkedResources()
Gets the collection of linked resources of message
|
Date |
getLocalDate()
Gets the local date of message
|
String |
getMessageId()
Gets or sets the message id
|
boolean |
getOriginalIsTnef()
Gets a value indicating
whether original EML message is in TNEF format.
|
Charset |
getPreferredTextEncoding()
Gets or sets preferred encoding for all text properties
|
MailPriority |
getPriority()
Gets or sets the priority of message
|
MailAddressCollection |
getReadReceiptTo()
Gets or sets the read receipt address.
|
MailAddressCollection |
getReplyToList()
Gets or sets the list of addresses
to reply to for the mail message
|
MailAddress |
getReversePath()
Gets or sets ReversePath address
|
MailAddress |
getSender()
Gets or sets sender address
|
MailSensitivity |
getSensitivity()
Gets or sets the sensitivity of message
|
String |
getSubject()
Gets or sets the subject line
|
Charset |
getSubjectEncoding()
Gets or sets the encoding of subject
|
double |
getTimeZoneOffset()
Gets or sets the Coordinated Universal Time (UTC)
offset for the message dates.
|
MailAddressCollection |
getTo()
Gets or sets the address collection that contains
the recipients of message
|
String |
getXMailer()
Gets or sets the X-Mailer the software
that created the e-mail message
|
int |
hashCode()
Returns a hash code for object
|
void |
importMessage(InputStream stream)
Imports message from stream
|
boolean |
isBodyHtml()
Gets or sets a value indicating
whether the message body is in Html
|
void |
isBodyHtml(boolean value)
Gets or sets a value indicating
whether the message body is in Html
|
boolean |
isDraft()
Gets or sets value that indicates whether or not a message has been sent.
|
void |
isDraft(boolean value)
Gets or sets value that indicates whether or not a message has been sent.
|
boolean |
isEncrypted()
Gets a value indicating whether the message is encrypted.
|
boolean |
isLocalDate()
Defines if date is local date
|
boolean |
isReadOnly()
Gets a value indicating
whether the message is read only
|
boolean |
isSigned()
Gets a value indicating whether the message is signed.
|
com.aspose.ms.System.Collections.Generic.IGenericEnumerator<MailMessage> |
iterator()
Returns an enumerator that iterates through a collection.
|
static MailMessage |
load(InputStream stream)
Load message from stream
|
static MailMessage |
load(InputStream stream,
LoadOptions options)
Load message from stream with additional options.
|
static MailMessage |
load(String fileName)
Load message from file
|
static MailMessage |
load(String fileName,
LoadOptions options)
Load message from file with additional options.
|
void |
recomposeTnefContent()
Composes the TNEF content.
|
MailMessage |
removeSignature()
Remove signature
|
void |
save(OutputStream stream)
Save message as a stream
|
void |
save(OutputStream stream,
SaveOptions options)
Save message as a stream with additional options.
|
void |
save(String fileName)
Save message as a file
|
void |
save(String fileName,
SaveOptions options)
Save message as a file with additional options.
|
void |
setBcc(MailAddressCollection value)
Gets or sets the address collection
that contains the BCC recipients of message
|
void |
setBody(String value)
Gets or sets the plain text representation of message's body.
|
void |
setBodyEncoding(Charset value)
Gets or sets encoding of body
|
void |
setCC(MailAddressCollection value)
Gets or sets the address collection
that contains the CC recipients
|
void |
setDate(Date value)
Gets or sets the date of message
|
void |
setDeliveryNotificationOptions(int value)
Gets or sets the delivery notifications
|
void |
setFrom(IMailAddress value)
Sets from address
|
void |
setFrom(MailAddress value)
Gets or sets the from address
|
void |
setHtmlBody(String value)
Gets or sets html body
|
void |
setMessageId(String value)
Gets or sets the message id
|
void |
setPreferredTextEncoding(Charset value)
Gets or sets preferred encoding for all text properties
|
void |
setPriority(MailPriority value)
Gets or sets the priority of message
|
void |
setReadReceiptTo(MailAddressCollection value)
Gets or sets the read receipt address.
|
void |
setReplyToList(MailAddressCollection value)
Gets or sets the list of addresses
to reply to for the mail message
|
void |
setReversePath(MailAddress value)
Gets or sets ReversePath address
|
void |
setSender(MailAddress value)
Gets or sets sender address
|
void |
setSensitivity(MailSensitivity value)
Gets or sets the sensitivity of message
|
void |
setSubject(String value)
Gets or sets the subject line
|
void |
setSubjectEncoding(Charset value)
Gets or sets the encoding of subject
|
void |
setTimeZoneOffset(double value)
Gets or sets the Coordinated Universal Time (UTC)
offset for the message dates.
|
void |
setTo(MailAddressCollection value)
Gets or sets the address collection that contains
the recipients of message
|
void |
setXMailer(String value)
Gets or sets the X-Mailer the software
that created the e-mail message
|
String |
toString()
Returns a string that represents the current object.
|
protected void |
unSubscribeFromEvents() |
static EmlValidationErrorCollection |
validateMessage(InputStream stream)
Validate eml message for corresponding to mime specification.
|
static EmlValidationErrorCollection |
validateMessage(String fileName)
Validate eml message for corresponding to mime specification.
|
public MailMessage(String from, String to)
Initializes a new instance of the MailMessage
class
from
- Sender addressto
- Recipient addresspublic MailMessage()
Initializes a new instance of the MailMessage
class
public MailMessage(boolean increaseCredit)
Initializes a new instance of the MailMessage
class
public MailMessage(String from, String to, String subject, String body)
Initializes a new instance of the MailMessage
class
from
- Sender addressto
- Recipient addresssubject
- Message subjectbody
- Message bodypublic MailMessage(MailAddress from, MailAddress to)
Initializes a new instance of the MailMessage
class
from
- Sender addressto
- Recipient addresspublic final Charset getPreferredTextEncoding()
Gets or sets preferred encoding for all text properties
getPreferredTextEncoding
in interface IPreferredTextEncodingProvider
public final void setPreferredTextEncoding(Charset value)
Gets or sets preferred encoding for all text properties
setPreferredTextEncoding
in interface IPreferredTextEncodingProvider
public MailAddress getFrom()
Gets or sets the from address
public void setFrom(MailAddress value)
Gets or sets the from address
public MailAddress getSender()
Gets or sets sender address
public void setSender(MailAddress value)
Gets or sets sender address
public MailAddress getReversePath()
Gets or sets ReversePath address
public void setReversePath(MailAddress value)
Gets or sets ReversePath address
public MailAddressCollection getReplyToList()
Gets or sets the list of addresses to reply to for the mail message
public void setReplyToList(MailAddressCollection value)
Gets or sets the list of addresses to reply to for the mail message
public MailAddressCollection getTo()
Gets or sets the address collection that contains the recipients of message
public void setTo(MailAddressCollection value)
Gets or sets the address collection that contains the recipients of message
public MailAddressCollection getBcc()
Gets or sets the address collection that contains the BCC recipients of message
public void setBcc(MailAddressCollection value)
Gets or sets the address collection that contains the BCC recipients of message
public MailAddressCollection getCC()
Gets or sets the address collection that contains the CC recipients
public void setCC(MailAddressCollection value)
Gets or sets the address collection that contains the CC recipients
public MailPriority getPriority()
Gets or sets the priority of message
public void setPriority(MailPriority value)
Gets or sets the priority of message
public MailSensitivity getSensitivity()
Gets or sets the sensitivity of message
public void setSensitivity(MailSensitivity value)
Gets or sets the sensitivity of message
public int getDeliveryNotificationOptions()
Gets or sets the delivery notifications
public void setDeliveryNotificationOptions(int value)
Gets or sets the delivery notifications
public String getSubject()
Gets or sets the subject line
getSubject
in interface IMessage
public void setSubject(String value)
Gets or sets the subject line
setSubject
in interface IMessage
public final double getTimeZoneOffset()
Gets or sets the Coordinated Universal Time (UTC) offset for the message dates. This property defines the time zone difference, between the local time and UTC.
public final void setTimeZoneOffset(double value)
Gets or sets the Coordinated Universal Time (UTC) offset for the message dates. This property defines the time zone difference, between the local time and UTC.
public Date getDate()
Gets or sets the date of message
public Date getLocalDate()
Gets the local date of message
public boolean isLocalDate()
Defines if date is local date
public void setDate(Date value)
Gets or sets the date of message
public String getMessageId()
Gets or sets the message id
public void setMessageId(String value)
Gets or sets the message id
public String getXMailer()
Gets or sets the X-Mailer the software that created the e-mail message
public void setXMailer(String value)
Gets or sets the X-Mailer the software that created the e-mail message
public Charset getSubjectEncoding()
Gets or sets the encoding of subject
public void setSubjectEncoding(Charset value)
Gets or sets the encoding of subject
public HeaderCollection getHeaders()
Gets headers collection of message
public String getHtmlBody()
Gets or sets html body
getHtmlBody
in interface IMessage
public void setHtmlBody(String value)
Gets or sets html body
setHtmlBody
in interface IMessage
public String getBody()
Gets or sets the plain text representation of message's body.
public void setBody(String value)
Gets or sets the plain text representation of message's body.
public final String getHtmlBodyText()
Gets the message htmlbody as plain text.
public Charset getBodyEncoding()
Gets or sets encoding of body
public void setBodyEncoding(Charset value)
Gets or sets encoding of body
public boolean isBodyHtml()
Gets or sets a value indicating whether the message body is in Html
public void isBodyHtml(boolean value)
Gets or sets a value indicating whether the message body is in Html
public boolean isSigned()
Gets a value indicating whether the message is signed.
public boolean isEncrypted()
Gets a value indicating whether the message is encrypted.
public boolean isReadOnly()
Gets a value indicating whether the message is read only
public boolean isDraft()
Gets or sets value that indicates whether or not a message has been sent.
public void isDraft(boolean value)
Gets or sets value that indicates whether or not a message has been sent.
public AttachmentCollection getAttachments()
Gets the collection of attachments of message
getAttachments
in interface IMessage
public LinkedResourceCollection getLinkedResources()
Gets the collection of linked resources of message
public AlternateViewCollection getAlternateViews()
Gets the collection of alternate views of message
public final int getBodyType()
Gets the type of the body.
getBodyType
in interface IMessage
public boolean getOriginalIsTnef()
Gets a value indicating whether original EML message is in TNEF format.
public final com.aspose.ms.System.Collections.Generic.IGenericCollection<MailAddress> getCc()
Gets CC recipients
public final void setFrom(IMailAddress value)
Sets from address
public static MailMessage load(String fileName)
Load message from file
fileName
- Message file name. The message file must be in eml or msg format.public static MailMessage load(InputStream stream)
Load message from stream
stream
- Stream that represents message in eml or msg formatpublic static MailMessage load(String fileName, LoadOptions options)
Load message from file with additional options.
fileName
- Source file pathString
.options
- Additional options LoadOptions
.MailMessage
.com.aspose.ms.System.ArgumentNullException
- If fileName
is null.public static MailMessage load(InputStream stream, LoadOptions options)
Load message from stream with additional options.
stream
- Source streamInputStream
.options
- Additional options LoadOptions
.MailMessage
.com.aspose.ms.System.ArgumentNullException
- If stream
is null.public static EmlValidationErrorCollection validateMessage(String fileName)
Validate eml message for corresponding to mime specification.
fileName
- A file name (eml).EmlValidationErrorCollection
containing the found validation error messages.com.aspose.ms.System.ArgumentException
- fileName
is null
or empty
.com.aspose.ms.System.IO.FileNotFoundException
- The specified fileName
doesn't exist.public static EmlValidationErrorCollection validateMessage(InputStream stream)
Validate eml message for corresponding to mime specification.
stream
- A stream containing the message in eml format.EmlValidationErrorCollection
containing the found validation error messages.com.aspose.ms.System.ArgumentNullException
- stream
is null
.public void importMessage(InputStream stream)
Imports message from stream
stream
- System.IO.Streampublic MailMessage deepClone()
Clones this instance
public final void recomposeTnefContent()
Composes the TNEF content. Note, that tnef attachment is composed if a message initially contained TNEF and was loaded without FileCompatibilityMode.PreserveTnefAttachments flag, That is this method doesn't create tnef message out of the regular one.
public String getHtmlBodyText(boolean showUrl)
Gets the message htmlbody as plain text.
showUrl
- Defines need to show URL in text.public String getHtmlBodyText(HyperlinkRenderingCallback hyperlinkRenderingCallback)
Gets the message htmlbody as plain text.
hyperlinkRenderingCallback
- Reference to custom method for handling rendering of hyperlink.public void save(String fileName)
Save message as a file
public void save(String fileName, SaveOptions options)
Save message as a file with additional options.
fileName
- Stream into which message is saved.options
- Additional options for savingSaveOptions
.public void save(OutputStream stream, SaveOptions options)
Save message as a stream with additional options.
stream
- Stream into which message is saved.options
- Additional options for savingSaveOptions
.public String toString()
Returns a string that represents the current object.
public int hashCode()
Returns a hash code for object
public boolean equals(Object obj)
Determines whether the specified Object is equal to the current Object.
public void save(OutputStream stream)
Save message as a stream
public final MailAddressCollection getReadReceiptTo()
Gets or sets the read receipt address.
Value: TheMailAddressCollection
that representspublic final void setReadReceiptTo(MailAddressCollection value)
Gets or sets the read receipt address.
Value: TheMailAddressCollection
that representspublic final MailMessage createReadReceipt(String from, String bodyText)
Creates the read receipt.
from
- String that represents the sender address.bodyText
- The message body text.
The default message body text will be applied if this parameter is null or empty.MailMessage
that represents the read receipt.public void addAlternateView(AlternateView view)
Add an alternate view to message
view
- Alternate view for addingpublic void addAttachment(Attachment attachment)
Add an attachment to message
attachment
- Attachment for addingpublic final void dispose()
Releases all resources used by the MailMessage
dispose
in interface com.aspose.ms.System.IDisposable
public MailMessage attachSignature(byte[] certificateRawData, String certificatePassword)
Creates a signed message. Creates a read-only copy of the specified MailMessage and adds a digital signature to it.
certificateRawData
- X.509 certificate.certificatePassword
- The password required to access the X.509 certificate datapublic static boolean checkSignature(String fileName)
Checks the signature of the specified eml file.
fileName
- A file name (eml).True
if signature is valid; otherwise, false
.com.aspose.ms.System.ArgumentException
- fileName
is null
or empty
.com.aspose.ms.System.IO.FileNotFoundException
- The specified fileName
doesn't exist.com.aspose.ms.System.NotSupportedException
- Signature type is not supported.com.aspose.ms.System.InvalidOperationException
- Mail message is not signed or signature type is not specified.public static boolean checkSignature(InputStream stream)
Checks the signature of the specified eml message.
stream
- A stream containing the message in eml format.True
if signature is valid; otherwise, false
.com.aspose.ms.System.ArgumentNullException
- stream
is null
.com.aspose.ms.System.NotSupportedException
- Signature type is not supported.com.aspose.ms.System.InvalidOperationException
- Mail message is not signed or signature type is not specified.public String[] checkSignature()
Checking signature exsisting MailMessage.
com.aspose.ms.System.InvalidOperationException
- Throws if Mail message is not signed or signature is not verified.public MailMessage removeSignature()
Remove signature
public MailMessage decrypt()
Decrypts this message
public MailMessage decrypt(byte[] certificateRawData, String certificatePassword)
Decrypts this message
certificateRawData
- System.Security.Cryptography.X509Certificates.X509Certificate2certificatePassword
- The password required to access the X.509 certificate datapublic MailMessage encrypt(byte[] certificateRawData, String certificatePassword)
Encrypts this message
certificate
- X509 certificate to encrypt messagepublic MailMessage dKIMSign(com.aspose.ms.System.Security.Cryptography.RSACryptoServiceProvider rsa, DKIMSignatureInfo signatureInfo)
Signs this message using DKIM (DomainKeys Identified Mail) signature.
rsa
- RSA class containing private key used for signing.signatureInfo
- DKIM signature information.public BounceResult checkBounced()
Checks whether this message can be treated as a bounce message.
BounceResult
.public final com.aspose.ms.System.Collections.Generic.IGenericEnumerator<MailMessage> iterator()
Returns an enumerator that iterates through a collection.
iterator
in interface com.aspose.ms.System.Collections.Generic.IGenericEnumerable<MailMessage>
iterator
in interface com.aspose.ms.System.Collections.IEnumerable<MailMessage>
iterator
in interface Iterable<MailMessage>
protected void dispose(boolean disposing)
Releases unmanaged and - optionally - managed resources
disposing
- true
to release both managed and unmanaged resources; false
to release only unmanaged resources.protected void unSubscribeFromEvents()