MailMessage

Inheritance: java.lang.Object, com.aspose.email.IPreferredTextEncodingProviderInternal

All Implemented Interfaces: com.aspose.ms.System.IDisposable, java.io.Closeable, com.aspose.email.IPreferredTextEncodingProvider, com.aspose.email.IMessage, com.aspose.ms.System.Collections.Generic.IGenericEnumerable

public class MailMessage extends IPreferredTextEncodingProviderInternal implements System.IDisposable, Closeable, IPreferredTextEncodingProvider, IMessage, 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.


The following example shows how to create a new Email Message and save with SaveOptions.

[Java]

MailMessage message = new MailMessage();
 // Set subject of the message, Html body and sender information
 message.setSubject("New message created by Aspose.Email for .NET");
 message.setHtmlBody("<b>This line is in bold.</b> <br/> <br/>" +
     "<font color=blue>This line is in blue color</font>");
 message.setFrom(new MailAddress("from@domain.com", "Sender Name", false));

 // Add TO recipients and Add CC recipients
 message.getTo().addMailAddress(new MailAddress("to1@domain.com", "Recipient 1", false));
 message.getTo().addMailAddress(new MailAddress("to2@domain.com", "Recipient 2", false));
 message.getCC().addMailAddress(new MailAddress("cc1@domain.com", "Recipient 3", false));
 message.getCC().addMailAddress(new MailAddress("cc2@domain.com", "Recipient 4", false));

 // Save message to EML, EMLX, MSG and MHTML formats
 message.save("CreateNewMailMessage_out.eml", SaveOptions.getDefaultEml());
 message.save("CreateNewMailMessage_out.emlx",
 SaveOptions.createSaveOptions(MailMessageSaveType.getEmlxFormat()));
 message.save("CreateNewMailMessage_out.msg", SaveOptions.getDefaultMsgUnicode());
 message.save("CreateNewMailMessage_out.mhtml", SaveOptions.getDefaultMhtml());

Constructors

ConstructorDescription
MailMessage(String from, String to)Initializes a new instance of the MailMessage class
MailMessage()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
MailMessage(MailAddress from, MailAddress to)Initializes a new instance of the MailMessage class

Methods

MethodDescription
addAlternateView(AlternateView view)Add an alternate view to message
addAttachment(Attachment attachment)Add an attachment to message
attachDetachedSignature(SmimeKey key)Creates a signed message.
attachSignature(byte[] certificateRawData, String certificatePassword)Creates a signed message.
attachSignature(byte[] certificateRawData, String certificatePassword, boolean detached)Creates a signed message.
attachSignature(SmimeKey key)Creates a signed message.
attachSignature(SmimeKey key, boolean detached)Creates a signed message.
checkBounced()Checks whether this message can be treated as a bounce message.
checkSignature()Checking signature exsisting MailMessage.
checkSignature(InputStream stream)Checks the signature of the specified eml message.
checkSignature(String fileName)Checks the signature of the specified eml file.
checkSignatureCert()Checking signature exsisting MailMessage.
close()
createReadReceipt(String from, String bodyText)Creates the read receipt.
dKIMSign(PrivateKey rsa, DKIMSignatureInfo signatureInfo)Signs this message using DKIM (DomainKeys Identified Mail) signature.
decrypt()Decrypts this message
decrypt(byte[] certificateRawData, String certificatePassword)Decrypts this message
decrypt(SmimeKey key)Decrypts this message
deepClone()Clones this instance
dispose()Releases all resources used by the MailMessage
encrypt(byte[] certificateRawData, String certificatePassword)Encrypts this message.
encrypt(SmimeKey key)Encrypts this message.
equals(Object obj)Determines whether the specified Object is equal to the current Object.
getAlternateViewContent(String mediaType)Gets the content as a string from the specified AlternateView.
getAlternateViews()Gets the collection of alternate views of message
getAttachments()Gets the collection of attachments of message
getBcc()Gets or sets the address collection that contains the BCC recipients of message
getBody()Gets or sets the plain text representation of message’s body.
getBodyEncoding()Gets or sets encoding of body
getBodyType()Gets the type of the body.
getCC()Gets or sets the address collection that contains the CC recipients
getCc()Gets CC recipients
getClass()
getDate()Gets or sets the date of message Specifies the date and time at which the creator of the message indicated that the message was complete and ready to enter the mail delivery system.
getDeliveryNotificationOptions()Gets or sets the delivery notifications
getEpilogue()Gets or sets an epilogue text.
getFrom()Gets or sets the from address
getHeaders()Gets headers collection of message
getHtmlBody()Gets or sets html body
getHtmlBodyText(boolean showUrl)Gets the message html body as plain text.
getHtmlBodyText(HyperlinkRenderingCallback hyperlinkRenderingCallback)Gets the message htmlbody as plain text.
getItemId()Represents identification information about message in a mailbox.
getLinkedResources()Gets the collection of linked resources of message
getLocalDate()Gets the local date of message
getMessageId()Gets or sets the message id
getOriginalIsTnef()Gets a value indicating whether original EML message is in TNEF format.
getPreamble()Gets or sets a preamble text.
getPreferredTextEncoding()Gets or sets preferred encoding for all text properties
getPriority()Gets or sets the priority of message
getReadReceiptTo()Gets or sets the read receipt address.
getReplyToList()Gets or sets the list of addresses to reply to for the mail message
getReversePath()Gets or sets ReversePath address
getSender()Gets or sets sender address
getSensitivity()Gets or sets the sensitivity of message
getSubject()Gets or sets the subject line
getSubjectEncoding()Gets or sets the encoding of subject
getTimeZoneOffset()Gets or sets the Coordinated Universal Time (UTC) offset for the message dates.
getTo()Gets or sets the address collection that contains the recipients of message
getXMailer()Gets or sets the X-Mailer the software that created the e-mail message
hashCode()Returns a hash code for object
importMessage(InputStream stream)Imports message from stream
isBodyHtml()Gets or sets a value indicating whether the message body is in Html
isBodyHtml(boolean value)Gets or sets a value indicating whether the message body is in Html
isDraft()Gets or sets value that indicates whether or not a message has been sent.
isDraft(boolean value)Gets or sets value that indicates whether or not a message has been sent.
isEncrypted()Gets a value indicating whether the message is encrypted.
isLocalDate()Defines if date is local date
isReadOnly()Gets a value indicating whether the message is read only
isSigned()Gets a value indicating whether the message is signed.
iterator()Returns an enumerator that iterates through a collection.
load(InputStream stream)Load message from stream
load(InputStream stream, LoadOptions options)Load message from stream with additional options.
load(String fileName)Load message from file
load(String fileName, LoadOptions options)Load message from file with additional options.
notify()
notifyAll()
recomposeTnefContent()Composes the TNEF content.
removeSignature()Remove signature
save(OutputStream stream)Save message as a stream
save(OutputStream stream, SaveOptions options)Save message as a stream with additional options.
save(String fileName)Save message as a file
save(String fileName, SaveOptions options)Save message as a file with additional options.
setBcc(MailAddressCollection value)Gets or sets the address collection that contains the BCC recipients of message
setBody(String value)Gets or sets the plain text representation of message’s body.
setBodyEncoding(Charset value)Gets or sets encoding of body
setCC(MailAddressCollection value)Gets or sets the address collection that contains the CC recipients
setDate(Date value)Gets or sets the date of message
setDeliveryNotificationOptions(int value)Gets or sets the delivery notifications
setEpilogue(String value)Gets or sets an epilogue text.
setFrom(IMailAddress value)Sets from address
setFrom(MailAddress value)Gets or sets the from address
setHtmlBody(String value)Gets or sets html body
setHtmlBody(String value, boolean detectEncoding)Sets html body.
setMessageId(String value)Gets or sets the message id
setPreamble(String value)Gets or sets a preamble text.
setPreferredTextEncoding(Charset value)Gets or sets preferred encoding for all text properties
setPriority(MailPriority value)Gets or sets the priority of message
setReadReceiptTo(MailAddressCollection value)Gets or sets the read receipt address.
setReplyToList(MailAddressCollection value)Gets or sets the list of addresses to reply to for the mail message
setReversePath(MailAddress value)Gets or sets ReversePath address
setSender(MailAddress value)Gets or sets sender address
setSensitivity(MailSensitivity value)Gets or sets the sensitivity of message
setSubject(String value)Gets or sets the subject line
setSubjectEncoding(Charset value)Gets or sets the encoding of subject
setTimeZoneOffset(double value)Gets or sets the Coordinated Universal Time (UTC) offset for the message dates.
setTo(MailAddressCollection value)Gets or sets the address collection that contains the recipients of message
setXMailer(String value)Gets or sets the X-Mailer the software that created the e-mail message
toString()Returns a string that represents the current object.
validateMessage(InputStream stream)Validate eml message for corresponding to mime specification.
validateMessage(String fileName)Validate eml message for corresponding to mime specification.
wait()
wait(long arg0)
wait(long arg0, int arg1)

MailMessage(String from, String to)

public MailMessage(String from, String to)

Initializes a new instance of the MailMessage class

Parameters:

ParameterTypeDescription
fromjava.lang.StringSender address
tojava.lang.StringRecipient address

MailMessage()

public MailMessage()

Initializes a new instance of the MailMessage class

MailMessage(String from, String to, String subject, String body)

public MailMessage(String from, String to, String subject, String body)

Initializes a new instance of the MailMessage class

Parameters:

ParameterTypeDescription
fromjava.lang.StringSender address
tojava.lang.StringRecipient address
subjectjava.lang.StringMessage subject
bodyjava.lang.StringMessage body

MailMessage(MailAddress from, MailAddress to)

public MailMessage(MailAddress from, MailAddress to)

Initializes a new instance of the MailMessage class

Parameters:

ParameterTypeDescription
fromMailAddressSender address
toMailAddressRecipient address

addAlternateView(AlternateView view)

public void addAlternateView(AlternateView view)

Add an alternate view to message

Parameters:

ParameterTypeDescription
viewAlternateViewAlternate view for adding

addAttachment(Attachment attachment)

public void addAttachment(Attachment attachment)

Add an attachment to message


The following example shows how to add Attachments to MailMessage.

[Java]

// Create an instance of MailMessage class
 MailMessage eml = new MailMessage();
 eml.setFrom(MailAddress.to_MailAddress("sender@from.com"));
 eml.setTo(MailAddressCollection.to_MailAddressCollection("receiver@to.com"));
 eml.setSubject("This is message");
 eml.setBody("This is body");

 // Load an attachment
 Attachment attachment = new Attachment("1.txt");

 // Add Multiple Attachment in instance of MailMessage class and Save message to disk
 eml.getAttachments().addItem(attachment);

 eml.addAttachment(new Attachment("1.jpg"));
 eml.addAttachment(new Attachment("1.doc"));
 eml.addAttachment(new Attachment("1.rar"));
 eml.addAttachment(new Attachment("1.pdf"));
 eml.save("AddAttachments.eml");

Parameters:

ParameterTypeDescription
attachmentAttachmentAttachment for adding

attachDetachedSignature(SmimeKey key)

public MailMessage attachDetachedSignature(SmimeKey key)

Creates a signed message. Creates a read-only copy of the specified MailMessage and adds a digital signature to it.


The following example shows how to attach a Certificate with AttachSignature Method.

[Java]

MailMessage msg = new MailMessage(“user@domain.com”, “receiver@domain.com”, “subject:Signed message only by AE”, “body:Test Body of signed message by AE”); MailMessage signed = msg.attachDetachedSignature(key); // load PFX file SmimeKey key = SmimeKey.loadPFX(pfxPath, “key”.toCharArray()); // load SmimeKey from private key string SmimeKey key = SmimeKey.loadPrivateKey(keyPath); // create SmimeKey from private key and X509 certificates SmimeKey key = new SmimeKey(privateKey, x509Certificate1, x509Certificate2);


Parameters:

ParameterTypeDescription
keySmimeKeySmimeKey with private key.

Returns: MailMessage - The signed MailMessage.

attachSignature(byte[] certificateRawData, String certificatePassword)

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.


The following example shows how to attach a Certificate with AttachSignature Method.

[Java]

MailMessage msg = new MailMessage("user@domain.com", "receiver@domain.com", "subject:Signed message only by AE",
     "body:Test Body of signed message by AE");
 MailMessage signed = msg.attachSignature(certData, true);

Parameters:

ParameterTypeDescription
certificateRawDatabyte[]X.509 certificate.
certificatePasswordjava.lang.StringThe password required to access the X.509 certificate data

Returns: MailMessage - The signed MailMessage.

attachSignature(byte[] certificateRawData, String certificatePassword, boolean detached)

public MailMessage attachSignature(byte[] certificateRawData, String certificatePassword, boolean detached)

Creates a signed message. Creates a read-only copy of the specified MailMessage and adds a digital signature to it.

Parameters:

ParameterTypeDescription
certificateRawDatabyte[]X.509 certificate.
certificatePasswordjava.lang.StringThe password required to access the X.509 certificate data
detachedboolean.If detached is true, the signature is detached.If detached is false(the default), the signature is not detached.

Returns: MailMessage - The signed MailMessage.

attachSignature(SmimeKey key)

public MailMessage attachSignature(SmimeKey key)

Creates a signed message. Creates a read-only copy of the specified MailMessage and adds a digital signature to it.


The following example shows how to attach a Certificate with AttachSignature Method.

[Java]

MailMessage msg = new MailMessage(“user@domain.com”, “receiver@domain.com”, “subject:Signed message only by AE”, “body:Test Body of signed message by AE”); MailMessage signed = msg.attachSignature(key); // load PFX file SmimeKey key = SmimeKey.loadPFX(pfxPath, “key”.toCharArray()); // load SmimeKey from private key string SmimeKey key = SmimeKey.loadPrivateKey(keyPath); // create SmimeKey from private key and X509 certificates SmimeKey key = new SmimeKey(privateKey, x509Certificate1, x509Certificate2);


Parameters:

ParameterTypeDescription
keySmimeKeySmimeKey with private key.

Returns: MailMessage - The signed MailMessage.

attachSignature(SmimeKey key, boolean detached)

public MailMessage attachSignature(SmimeKey key, boolean detached)

Creates a signed message. Creates a read-only copy of the specified MailMessage and adds a digital signature to it.


The following example shows how to attach a Certificate with AttachSignature Method.

[Java]

MailMessage msg = new MailMessage(“user@domain.com”, “receiver@domain.com”, “subject:Signed message only by AE”, “body:Test Body of signed message by AE”); // create signed mail with detached signature MailMessage signedDetached = msg.attachSignature(key, true); // create signed mail with attached signature MailMessage signedAttached = msg.attachSignature(key, false); // load PFX file SmimeKey key = SmimeKey.loadPFX(pfxPath, “key”.toCharArray()); // load SmimeKey from private key string SmimeKey key = SmimeKey.loadPrivateKey(keyPath); // create SmimeKey from private key and X509 certificates SmimeKey key = new SmimeKey(privateKey, x509Certificate1, x509Certificate2);


Parameters:

ParameterTypeDescription
keySmimeKeySmimeKey with private key.
detachedboolean.If detached is true, the signature is detached.

Returns: MailMessage - The signed MailMessage.

checkBounced()

public BounceResult checkBounced()

Checks whether this message can be treated as a bounce message.

Returns: BounceResult - Result of checkingBounceResult.

checkSignature()

public String[] checkSignature()

Checking signature exsisting MailMessage.

Returns: java.lang.String[] - X.509 signers certificates

checkSignature(InputStream stream)

public static boolean checkSignature(InputStream stream)

Checks the signature of the specified eml message.

Parameters:

ParameterTypeDescription
streamjava.io.InputStreamA stream containing the message in eml format.

Returns: boolean - True if signature is valid; otherwise, false .

checkSignature(String fileName)

public static boolean checkSignature(String fileName)

Checks the signature of the specified eml file.

Parameters:

ParameterTypeDescription
fileNamejava.lang.StringA file name (eml).

Returns: boolean - True if signature is valid; otherwise, false .

checkSignatureCert()

public List<X509Certificate> checkSignatureCert()

Checking signature exsisting MailMessage.

Returns: java.util.List<java.security.cert.X509Certificate> - X.509 signers certificates

close()

public void close()

createReadReceipt(String from, String bodyText)

public final MailMessage createReadReceipt(String from, String bodyText)

Creates the read receipt.

Parameters:

ParameterTypeDescription
fromjava.lang.StringString that represents the sender address.
bodyTextjava.lang.StringThe message body text. The default message body text will be applied if this parameter is null or empty.

Returns: MailMessage - A newly created MailMessage that represents the read receipt.

dKIMSign(PrivateKey rsa, DKIMSignatureInfo signatureInfo)

public MailMessage dKIMSign(PrivateKey rsa, DKIMSignatureInfo signatureInfo)

Signs this message using DKIM (DomainKeys Identified Mail) signature.


The following example shows how to sign Emails with DKIM.

[Java]

String privateKeyFile = "key2.pem";

 RSACryptoServiceProvider rsa = PemReader.getPrivateKey(privateKeyFile);
 DKIMSignatureInfo signInfo = new DKIMSignatureInfo("test", "some_email.com");
 signInfo.getHeaders().addItem("From");

 signInfo.getHeaders().addItem("Subject");

 MailMessage mailMessage = new MailMessage("useremail@gmail.com", "test@gmail.com")
 mailMessage.setSubject("Signed DKIM message text body");
 mailMessage.setBody("This is a text body signed DKIM message");

 MailMessage signedMsg = mailMessage.dKIMSign(rsa, signInfo);

Parameters:

ParameterTypeDescription
rsajava.security.PrivateKeyRSA class containing private key used for signing.
signatureInfoDKIMSignatureInfoDKIM signature information.

Returns: MailMessage -

decrypt()

public MailMessage decrypt()

Decrypts this message

Returns: MailMessage - Decrypted E-mail message

decrypt(byte[] certificateRawData, String certificatePassword)

public MailMessage decrypt(byte[] certificateRawData, String certificatePassword)

Decrypts this message

Parameters:

ParameterTypeDescription
certificateRawDatabyte[]X509 certificate to decrypt message
certificatePasswordjava.lang.StringThe password required to access the X.509 certificate data

Returns: MailMessage - E-mail message

decrypt(SmimeKey key)

public MailMessage decrypt(SmimeKey key)

Decrypts this message


The following example shows how to encrypt messages.

[Java]

// Create a message MailMessage eml = new MailMessage(); eml.setFrom(MailAddress.to_MailAddress(“atneostthaecrcount@gmail.com”)); eml.setTo(MailAddressCollection.to_MailAddressCollection(“atneostthaecrcount@gmail.com”)); eml.setSubject(“Test subject”); eml.setBody(“Test Body”);

// load PFX file SmimeKey key = SmimeKey.loadPFX(pfxPath, “key”.toCharArray()); // load SmimeKey from private key string SmimeKey key = SmimeKey.loadPrivateKey(keyPath); // create SmimeKey from private key and X509 certificates SmimeKey key = new SmimeKey(privateKey, x509Certificate1, x509Certificate2);

// Decrypt the message MailMessage eml = eml.decrypt(key); System.out.println(encryptedEml.isEncrypted() ? “It’s encrypted” : “It’s NOT encrypted”);


Parameters:

ParameterTypeDescription
keySmimeKeySmimeKey with the private key

Returns: MailMessage - Decrypted E-mail message

deepClone()

public MailMessage deepClone()

Clones this instance

Returns: MailMessage - MailMessage that is a copy of the current instance

dispose()

public final void dispose()

Releases all resources used by the MailMessage

encrypt(byte[] certificateRawData, String certificatePassword)

public MailMessage encrypt(byte[] certificateRawData, String certificatePassword)

Encrypts this message.


The following example shows how to encrypt messages.

[Java]

// Create a message MailMessage eml = new MailMessage(); eml.setFrom(MailAddress.to_MailAddress(“atneostthaecrcount@gmail.com”)); eml.setTo(MailAddressCollection.to_MailAddressCollection(“atneostthaecrcount@gmail.com”)); eml.setSubject(“Test subject”); eml.setBody(“Test Body”);

// Encrypt the message MailMessage encryptedEml = eml.encrypt(certData, certPass); System.out.println(encryptedEml.isEncrypted() ? “It’s encrypted” : “It’s NOT encrypted”);


Parameters:

ParameterTypeDescription
certificateRawDatabyte[]X509 certificate to encrypt the message.
certificatePasswordjava.lang.StringPassword for the X509 certificate.

Returns: MailMessage - Encrypted email message.

encrypt(SmimeKey key)

public MailMessage encrypt(SmimeKey key)

Encrypts this message.


The following example shows how to encrypt messages.

[Java]

// Create a message MailMessage eml = new MailMessage(); eml.setFrom(MailAddress.to_MailAddress(“atneostthaecrcount@gmail.com”)); eml.setTo(MailAddressCollection.to_MailAddressCollection(“atneostthaecrcount@gmail.com”)); eml.setSubject(“Test subject”); eml.setBody(“Test Body”);

// load PFX file SmimeKey key = SmimeKey.loadPFX(pfxPath, “key”.toCharArray()); // load SmimeKey from certificate string SmimeKey key = SmimeKey.loadCertificate(crtPath); // create SmimeKey from private key and X509 certificates SmimeKey key = new SmimeKey(privateKey, x509Certificate1, x509Certificate2);

// Encrypt the message MailMessage encryptedEml = eml.encrypt(key); System.out.println(encryptedEml.isEncrypted() ? “It’s encrypted” : “It’s NOT encrypted”);


Parameters:

ParameterTypeDescription
keySmimeKeySmimeKey with the public certificate.

Returns: MailMessage - Encrypted email message.

equals(Object obj)

public boolean equals(Object obj)

Determines whether the specified Object is equal to the current Object.

Parameters:

ParameterTypeDescription
objjava.lang.ObjectThe Object to compare with the current Object.

Returns: boolean - Returns a boolean indicating if the passed in object obj is Equal to this.

getAlternateViewContent(String mediaType)

public final String getAlternateViewContent(String mediaType)

Gets the content as a string from the specified AlternateView.

Parameters:

ParameterTypeDescription
mediaTypejava.lang.StringMediaType of needed AlternateView.

Returns: java.lang.String -

getAlternateViews()

public AlternateViewCollection getAlternateViews()

Gets the collection of alternate views of message

Returns: AlternateViewCollection

getAttachments()

public AttachmentCollection getAttachments()

Gets the collection of attachments of message

Returns: AttachmentCollection

getBcc()

public MailAddressCollection getBcc()

Gets or sets the address collection that contains the BCC recipients of message

Returns: MailAddressCollection

getBody()

public String getBody()

Gets or sets the plain text representation of message’s body. If the text/plain part is present in a message, the propery returns its text data. Otherwise, property returns the text content of the HtmlBody property without html markup.

Returns: java.lang.String

getBodyEncoding()

public Charset getBodyEncoding()

Gets or sets encoding of body

Returns: java.nio.charset.Charset

getBodyType()

public final int getBodyType()

Gets the type of the body.

Returns: int

getCC()

public MailAddressCollection getCC()

Gets or sets the address collection that contains the CC recipients

Returns: MailAddressCollection

getCc()

public final System.Collections.Generic.IGenericCollection<MailAddress> getCc()

Gets CC recipients

Returns: com.aspose.ms.System.Collections.Generic.IGenericCollection<com.aspose.email.MailAddress>

getClass()

public final native Class<?> getClass()

Returns: java.lang.Class

getDate()

public Date getDate()

Gets or sets the date of message Specifies the date and time at which the creator of the message indicated that the message was complete and ready to enter the mail delivery system.

Returns: java.util.Date

getDeliveryNotificationOptions()

public int getDeliveryNotificationOptions()

Gets or sets the delivery notifications

Returns: int

getEpilogue()

public final String getEpilogue()

Gets or sets an epilogue text. It is located after the last boundary.

Value: The string value that represents an epilogue.

Returns: java.lang.String

getFrom()

public MailAddress getFrom()

Gets or sets the from address

Returns: MailAddress

getHeaders()

public HeaderCollection getHeaders()

Gets headers collection of message

Returns: HeaderCollection

getHtmlBody()

public String getHtmlBody()

Gets or sets html body

Returns: java.lang.String

getHtmlBodyText(boolean showUrl)

public String getHtmlBodyText(boolean showUrl)

Gets the message html body as plain text. This method parses the HtmlBody property and returns plain text content ignoring the html markup.

The following example shows how to get an email message\ufffds HTML body as plain text.


The following example shows how to detect File Formats of Email Message.

[Java]

MailMessage eml = MailMessage.load("HtmlWithUrlSample.eml");
 String bodyWithUrl = eml.getHtmlBodyText(true);// body will contain URL
 String bodyWithoutUrl = eml.getHtmlBodyText(false);// body will not contain URL

 System.out.println("Body with URL: " + bodyWithUrl);
 System.out.println("Body without URL: " + bodyWithoutUrl);

Parameters:

ParameterTypeDescription
showUrlbooleanDefines need to show URL in text.

Returns: java.lang.String

getHtmlBodyText(HyperlinkRenderingCallback hyperlinkRenderingCallback)

public String getHtmlBodyText(HyperlinkRenderingCallback hyperlinkRenderingCallback)

Gets the message htmlbody as plain text.

Parameters:

ParameterTypeDescription
hyperlinkRenderingCallbackHyperlinkRenderingCallbackReference to custom method for handling rendering of hyperlink.

Returns: java.lang.String - Result string of custom handling rendering of hyperlink.

getItemId()

public MailboxInfo getItemId()

Represents identification information about message in a mailbox.

Returns: MailboxInfo

getLinkedResources()

public LinkedResourceCollection getLinkedResources()

Gets the collection of linked resources of message

Returns: LinkedResourceCollection

getLocalDate()

public Date getLocalDate()

Gets the local date of message

Returns: java.util.Date - A local date of message

getMessageId()

public String getMessageId()

Gets or sets the message id

Returns: java.lang.String

getOriginalIsTnef()

public boolean getOriginalIsTnef()

Gets a value indicating whether original EML message is in TNEF format.

Returns: boolean

getPreamble()

public final String getPreamble()

Gets or sets a preamble text. It is located before the first boundary and generally includes an explanatory note to non-MIME conformant readers.

Value: The string value that represents a preamble.

Returns: java.lang.String

getPreferredTextEncoding()

public final Charset getPreferredTextEncoding()

Gets or sets preferred encoding for all text properties

Returns: java.nio.charset.Charset

getPriority()

public MailPriority getPriority()

Gets or sets the priority of message

Returns: MailPriority

getReadReceiptTo()

public final MailAddressCollection getReadReceiptTo()

Gets or sets the read receipt address.

Value: The MailAddressCollection that represents

Returns: MailAddressCollection

getReplyToList()

public MailAddressCollection getReplyToList()

Gets or sets the list of addresses to reply to for the mail message

Returns: MailAddressCollection

getReversePath()

public MailAddress getReversePath()

Gets or sets ReversePath address

Returns: MailAddress

getSender()

public MailAddress getSender()

Gets or sets sender address

Returns: MailAddress

getSensitivity()

public MailSensitivity getSensitivity()

Gets or sets the sensitivity of message

Returns: MailSensitivity

getSubject()

public String getSubject()

Gets or sets the subject line

Returns: java.lang.String

getSubjectEncoding()

public Charset getSubjectEncoding()

Gets or sets the encoding of subject

Returns: java.nio.charset.Charset

getTimeZoneOffset()

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.

Returns: double - A number of milliseconds.

getTo()

public MailAddressCollection getTo()

Gets or sets the address collection that contains the recipients of message

Returns: MailAddressCollection

getXMailer()

public String getXMailer()

Gets or sets the X-Mailer the software that created the e-mail message

Returns: java.lang.String

hashCode()

public int hashCode()

Returns a hash code for object

Returns: int -

importMessage(InputStream stream)

public void importMessage(InputStream stream)

Imports message from stream

Parameters:

ParameterTypeDescription
streamjava.io.InputStreamSystem.IO.Stream

isBodyHtml()

public boolean isBodyHtml()

Gets or sets a value indicating whether the message body is in Html

Returns: boolean

isBodyHtml(boolean value)

public void isBodyHtml(boolean value)

Gets or sets a value indicating whether the message body is in Html

Parameters:

ParameterTypeDescription
valueboolean

isDraft()

public boolean isDraft()

Gets or sets value that indicates whether or not a message has been sent.

Returns: boolean

isDraft(boolean value)

public void isDraft(boolean value)

Gets or sets value that indicates whether or not a message has been sent.

Parameters:

ParameterTypeDescription
valueboolean

isEncrypted()

public boolean isEncrypted()

Gets a value indicating whether the message is encrypted.

Returns: boolean

isLocalDate()

public boolean isLocalDate()

Defines if date is local date

Returns: boolean - true if date is local date

isReadOnly()

public boolean isReadOnly()

Gets a value indicating whether the message is read only

Returns: boolean

isSigned()

public boolean isSigned()

Gets a value indicating whether the message is signed.

Returns: boolean

iterator()

public final System.Collections.Generic.IGenericEnumerator<MailMessage> iterator()

Returns an enumerator that iterates through a collection.

Returns: com.aspose.ms.System.Collections.Generic.IGenericEnumerator<com.aspose.email.MailMessage> - An IEnumerator object that can be used to iterate through the collection.

load(InputStream stream)

public static MailMessage load(InputStream stream)

Load message from stream

Parameters:

ParameterTypeDescription
streamjava.io.InputStreamStream that represents message in eml or msg format

Returns: MailMessage - E-mail message

load(InputStream stream, LoadOptions options)

public static MailMessage load(InputStream stream, LoadOptions options)

Load message from stream with additional options.

Parameters:

ParameterTypeDescription
streamjava.io.InputStreamSource streamjava.io.InputStream.
optionsLoadOptionsAdditional options LoadOptions.

Returns: MailMessage - Mail messageMailMessage.

load(String fileName)

public static MailMessage load(String fileName)

Load message from file

Parameters:

ParameterTypeDescription
fileNamejava.lang.StringMessage file name. The message file must be in eml or msg format.

Returns: MailMessage - E-mail message

load(String fileName, LoadOptions options)

public static MailMessage load(String fileName, LoadOptions options)

Load message from file with additional options.


The following example shows how to load a Message with Load Options.

[Java]

// Load Eml, html, mhtml, msg and dat file
 MailMessage.load("Message.eml", new EmlLoadOptions());
 MailMessage.load("description.html", new HtmlLoadOptions());
 MailMessage.load("Message.mhtml", new MhtmlLoadOptions());
 MailMessage.load("Message.msg", new MsgLoadOptions());

 // loading with custom options
 EmlLoadOptions emlLoadOptions = new EmlLoadOptions();
 emlLoadOptions.setPreferredTextEncoding(Charset.forName("utf-8"));
 emlLoadOptions.setPreserveTnefAttachments(true);

 MailMessage.load("description.html", emlLoadOptions);

 HtmlLoadOptions htmlLoadOptions = new HtmlLoadOptions();
 htmlLoadOptions.setPreferredTextEncoding(Charset.forName("utf-8"));
 htmlLoadOptions.shouldAddPlainTextView(true);
 htmlLoadOptions.setPathToResources(htmlImagesFolder);

 MailMessage.load("description.html", htmlLoadOptions);

Parameters:

ParameterTypeDescription
fileNamejava.lang.StringSource file path String.
optionsLoadOptionsAdditional options LoadOptions.

Returns: MailMessage - Mail message MailMessage.

notify()

public final native void notify()

notifyAll()

public final native void notifyAll()

recomposeTnefContent()

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.

removeSignature()

public MailMessage removeSignature()

Remove signature

Returns: MailMessage - E-mail message

save(OutputStream stream)

public void save(OutputStream stream)

Save message as a stream

Parameters:

ParameterTypeDescription
streamjava.io.OutputStreamStream into which message is saved

save(OutputStream stream, SaveOptions options)

public void save(OutputStream stream, SaveOptions options)

Save message as a stream with additional options.

Parameters:

ParameterTypeDescription
streamjava.io.OutputStreamStream into which message is saved.
optionsSaveOptionsAdditional options for savingSaveOptions.

save(String fileName)

public void save(String fileName)

Save message as a file

Parameters:

ParameterTypeDescription
fileNamejava.lang.StringName of a file to save message.

save(String fileName, SaveOptions options)

public void save(String fileName, SaveOptions options)

Save message as a file with additional options.


The following example shows how to save an email message as HTML with embedded images.

[Java]

String fileName = "EmailWithAttachEmbedded.eml";
 MailMessage eml = MailMessage.load(fileName);

 HtmlSaveOptions options = new HtmlSaveOptions();
 options.setResourceRenderingMode(ResourceRenderingMode.EmbedIntoHtml);
 eml.save(fileName + ".html", options);

Parameters:

ParameterTypeDescription
fileNamejava.lang.StringStream into which message is saved.
optionsSaveOptionsAdditional options for savingSaveOptions.

setBcc(MailAddressCollection value)

public void setBcc(MailAddressCollection value)

Gets or sets the address collection that contains the BCC recipients of message

Parameters:

ParameterTypeDescription
valueMailAddressCollection

setBody(String value)

public void setBody(String value)

Gets or sets the plain text representation of message’s body. If the text/plain part is present in a message, the propery returns its text data. Otherwise, property returns the text content of the HtmlBody property without html markup.

Parameters:

ParameterTypeDescription
valuejava.lang.String

setBodyEncoding(Charset value)

public void setBodyEncoding(Charset value)

Gets or sets encoding of body

Parameters:

ParameterTypeDescription
valuejava.nio.charset.Charset

setCC(MailAddressCollection value)

public void setCC(MailAddressCollection value)

Gets or sets the address collection that contains the CC recipients

Parameters:

ParameterTypeDescription
valueMailAddressCollection

setDate(Date value)

public void setDate(Date value)

Gets or sets the date of message

Parameters:

ParameterTypeDescription
valuejava.util.Date

setDeliveryNotificationOptions(int value)

public void setDeliveryNotificationOptions(int value)

Gets or sets the delivery notifications

Parameters:

ParameterTypeDescription
valueint

setEpilogue(String value)

public final void setEpilogue(String value)

Gets or sets an epilogue text. It is located after the last boundary.

Value: The string value that represents an epilogue.

Parameters:

ParameterTypeDescription
valuejava.lang.String

setFrom(IMailAddress value)

public final void setFrom(IMailAddress value)

Sets from address

Parameters:

ParameterTypeDescription
valueIMailAddressA from address

setFrom(MailAddress value)

public void setFrom(MailAddress value)

Gets or sets the from address

Parameters:

ParameterTypeDescription
valueMailAddress

setHtmlBody(String value)

public void setHtmlBody(String value)

Gets or sets html body

Parameters:

ParameterTypeDescription
valuejava.lang.String

setHtmlBody(String value, boolean detectEncoding)

public void setHtmlBody(String value, boolean detectEncoding)

Sets html body.

Parameters:

ParameterTypeDescription
valuejava.lang.StringThe HtmlBody content text.
detectEncodingbooleanDetect body encoding if no encoding is specified for the MailMessage.

setMessageId(String value)

public void setMessageId(String value)

Gets or sets the message id

Parameters:

ParameterTypeDescription
valuejava.lang.String

setPreamble(String value)

public final void setPreamble(String value)

Gets or sets a preamble text. It is located before the first boundary and generally includes an explanatory note to non-MIME conformant readers.

Value: The string value that represents a preamble.

Parameters:

ParameterTypeDescription
valuejava.lang.String

setPreferredTextEncoding(Charset value)

public final void setPreferredTextEncoding(Charset value)

Gets or sets preferred encoding for all text properties

Parameters:

ParameterTypeDescription
valuejava.nio.charset.Charset

setPriority(MailPriority value)

public void setPriority(MailPriority value)

Gets or sets the priority of message

Parameters:

ParameterTypeDescription
valueMailPriority

setReadReceiptTo(MailAddressCollection value)

public final void setReadReceiptTo(MailAddressCollection value)

Gets or sets the read receipt address.

Value: The MailAddressCollection that represents

Parameters:

ParameterTypeDescription
valueMailAddressCollection

setReplyToList(MailAddressCollection value)

public void setReplyToList(MailAddressCollection value)

Gets or sets the list of addresses to reply to for the mail message

Parameters:

ParameterTypeDescription
valueMailAddressCollection

setReversePath(MailAddress value)

public void setReversePath(MailAddress value)

Gets or sets ReversePath address

Parameters:

ParameterTypeDescription
valueMailAddress

setSender(MailAddress value)

public void setSender(MailAddress value)

Gets or sets sender address

Parameters:

ParameterTypeDescription
valueMailAddress

setSensitivity(MailSensitivity value)

public void setSensitivity(MailSensitivity value)

Gets or sets the sensitivity of message

Parameters:

ParameterTypeDescription
valueMailSensitivity

setSubject(String value)

public void setSubject(String value)

Gets or sets the subject line

Parameters:

ParameterTypeDescription
valuejava.lang.String

setSubjectEncoding(Charset value)

public void setSubjectEncoding(Charset value)

Gets or sets the encoding of subject

Parameters:

ParameterTypeDescription
valuejava.nio.charset.Charset

setTimeZoneOffset(double value)

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.

Parameters:

ParameterTypeDescription
valuedoubleA number of milliseconds.

setTo(MailAddressCollection value)

public void setTo(MailAddressCollection value)

Gets or sets the address collection that contains the recipients of message

Parameters:

ParameterTypeDescription
valueMailAddressCollection

setXMailer(String value)

public void setXMailer(String value)

Gets or sets the X-Mailer the software that created the e-mail message

Parameters:

ParameterTypeDescription
valuejava.lang.String

toString()

public String toString()

Returns a string that represents the current object.

Returns: java.lang.String - A string that represents the current object.

validateMessage(InputStream stream)

public static EmlValidationErrorCollection validateMessage(InputStream stream)

Validate eml message for corresponding to mime specification.

Parameters:

ParameterTypeDescription
streamjava.io.InputStreamA stream containing the message in eml format.

Returns: EmlValidationErrorCollection - A EmlValidationErrorCollection containing the found validation error messages.

validateMessage(String fileName)

public static EmlValidationErrorCollection validateMessage(String fileName)

Validate eml message for corresponding to mime specification.

Parameters:

ParameterTypeDescription
fileNamejava.lang.StringA file name (eml).

Returns: EmlValidationErrorCollection - A EmlValidationErrorCollection containing the found validation error messages.

wait()

public final void wait()

wait(long arg0)

public final native void wait(long arg0)

Parameters:

ParameterTypeDescription
arg0long

wait(long arg0, int arg1)

public final void wait(long arg0, int arg1)

Parameters:

ParameterTypeDescription
arg0long
arg1int