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
Constructor | Description |
---|---|
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
Method | Description |
---|---|
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:
Parameter | Type | Description |
---|---|---|
from | java.lang.String | Sender address |
to | java.lang.String | Recipient 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:
Parameter | Type | Description |
---|---|---|
from | java.lang.String | Sender address |
to | java.lang.String | Recipient address |
subject | java.lang.String | Message subject |
body | java.lang.String | Message body |
MailMessage(MailAddress from, MailAddress to)
public MailMessage(MailAddress from, MailAddress to)
Initializes a new instance of the MailMessage class
Parameters:
Parameter | Type | Description |
---|---|---|
from | MailAddress | Sender address |
to | MailAddress | Recipient address |
addAlternateView(AlternateView view)
public void addAlternateView(AlternateView view)
Add an alternate view to message
Parameters:
Parameter | Type | Description |
---|---|---|
view | AlternateView | Alternate 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:
Parameter | Type | Description |
---|---|---|
attachment | Attachment | Attachment 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:
Parameter | Type | Description |
---|---|---|
key | SmimeKey | SmimeKey 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:
Parameter | Type | Description |
---|---|---|
certificateRawData | byte[] | X.509 certificate. |
certificatePassword | java.lang.String | The 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:
Parameter | Type | Description |
---|---|---|
certificateRawData | byte[] | X.509 certificate. |
certificatePassword | java.lang.String | The password required to access the X.509 certificate data |
detached | boolean | .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:
Parameter | Type | Description |
---|---|---|
key | SmimeKey | SmimeKey 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:
Parameter | Type | Description |
---|---|---|
key | SmimeKey | SmimeKey with private key. |
detached | boolean | .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:
Parameter | Type | Description |
---|---|---|
stream | java.io.InputStream | A 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:
Parameter | Type | Description |
---|---|---|
fileName | java.lang.String | A 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:
Parameter | Type | Description |
---|---|---|
from | java.lang.String | String that represents the sender address. |
bodyText | java.lang.String | The 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:
Parameter | Type | Description |
---|---|---|
rsa | java.security.PrivateKey | RSA class containing private key used for signing. |
signatureInfo | DKIMSignatureInfo | DKIM 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:
Parameter | Type | Description |
---|---|---|
certificateRawData | byte[] | X509 certificate to decrypt message |
certificatePassword | java.lang.String | The 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:
Parameter | Type | Description |
---|---|---|
key | SmimeKey | SmimeKey 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:
Parameter | Type | Description |
---|---|---|
certificateRawData | byte[] | X509 certificate to encrypt the message. |
certificatePassword | java.lang.String | Password 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:
Parameter | Type | Description |
---|---|---|
key | SmimeKey | SmimeKey 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:
Parameter | Type | Description |
---|---|---|
obj | java.lang.Object | The 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:
Parameter | Type | Description |
---|---|---|
mediaType | java.lang.String | MediaType 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:
Parameter | Type | Description |
---|---|---|
showUrl | boolean | Defines 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:
Parameter | Type | Description |
---|---|---|
hyperlinkRenderingCallback | HyperlinkRenderingCallback | Reference 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:
Parameter | Type | Description |
---|---|---|
stream | java.io.InputStream | System.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:
Parameter | Type | Description |
---|---|---|
value | boolean |
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:
Parameter | Type | Description |
---|---|---|
value | boolean |
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:
Parameter | Type | Description |
---|---|---|
stream | java.io.InputStream | Stream 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:
Parameter | Type | Description |
---|---|---|
stream | java.io.InputStream | Source streamjava.io.InputStream. |
options | LoadOptions | Additional options LoadOptions. |
Returns: MailMessage - Mail messageMailMessage.
load(String fileName)
public static MailMessage load(String fileName)
Load message from file
Parameters:
Parameter | Type | Description |
---|---|---|
fileName | java.lang.String | Message 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:
Parameter | Type | Description |
---|---|---|
fileName | java.lang.String | Source file path String. |
options | LoadOptions | Additional 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:
Parameter | Type | Description |
---|---|---|
stream | java.io.OutputStream | Stream 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:
Parameter | Type | Description |
---|---|---|
stream | java.io.OutputStream | Stream into which message is saved. |
options | SaveOptions | Additional options for savingSaveOptions. |
save(String fileName)
public void save(String fileName)
Save message as a file
Parameters:
Parameter | Type | Description |
---|---|---|
fileName | java.lang.String | Name 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:
Parameter | Type | Description |
---|---|---|
fileName | java.lang.String | Stream into which message is saved. |
options | SaveOptions | Additional 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:
Parameter | Type | Description |
---|---|---|
value | MailAddressCollection |
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:
Parameter | Type | Description |
---|---|---|
value | java.lang.String |
setBodyEncoding(Charset value)
public void setBodyEncoding(Charset value)
Gets or sets encoding of body
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.nio.charset.Charset |
setCC(MailAddressCollection value)
public void setCC(MailAddressCollection value)
Gets or sets the address collection that contains the CC recipients
Parameters:
Parameter | Type | Description |
---|---|---|
value | MailAddressCollection |
setDate(Date value)
public void setDate(Date value)
Gets or sets the date of message
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.util.Date |
setDeliveryNotificationOptions(int value)
public void setDeliveryNotificationOptions(int value)
Gets or sets the delivery notifications
Parameters:
Parameter | Type | Description |
---|---|---|
value | int |
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:
Parameter | Type | Description |
---|---|---|
value | java.lang.String |
setFrom(IMailAddress value)
public final void setFrom(IMailAddress value)
Sets from address
Parameters:
Parameter | Type | Description |
---|---|---|
value | IMailAddress | A from address |
setFrom(MailAddress value)
public void setFrom(MailAddress value)
Gets or sets the from address
Parameters:
Parameter | Type | Description |
---|---|---|
value | MailAddress |
setHtmlBody(String value)
public void setHtmlBody(String value)
Gets or sets html body
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.lang.String |
setHtmlBody(String value, boolean detectEncoding)
public void setHtmlBody(String value, boolean detectEncoding)
Sets html body.
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.lang.String | The HtmlBody content text. |
detectEncoding | boolean | Detect 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:
Parameter | Type | Description |
---|---|---|
value | java.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:
Parameter | Type | Description |
---|---|---|
value | java.lang.String |
setPreferredTextEncoding(Charset value)
public final void setPreferredTextEncoding(Charset value)
Gets or sets preferred encoding for all text properties
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.nio.charset.Charset |
setPriority(MailPriority value)
public void setPriority(MailPriority value)
Gets or sets the priority of message
Parameters:
Parameter | Type | Description |
---|---|---|
value | MailPriority |
setReadReceiptTo(MailAddressCollection value)
public final void setReadReceiptTo(MailAddressCollection value)
Gets or sets the read receipt address.
Value: The MailAddressCollection that represents
Parameters:
Parameter | Type | Description |
---|---|---|
value | MailAddressCollection |
setReplyToList(MailAddressCollection value)
public void setReplyToList(MailAddressCollection value)
Gets or sets the list of addresses to reply to for the mail message
Parameters:
Parameter | Type | Description |
---|---|---|
value | MailAddressCollection |
setReversePath(MailAddress value)
public void setReversePath(MailAddress value)
Gets or sets ReversePath address
Parameters:
Parameter | Type | Description |
---|---|---|
value | MailAddress |
setSender(MailAddress value)
public void setSender(MailAddress value)
Gets or sets sender address
Parameters:
Parameter | Type | Description |
---|---|---|
value | MailAddress |
setSensitivity(MailSensitivity value)
public void setSensitivity(MailSensitivity value)
Gets or sets the sensitivity of message
Parameters:
Parameter | Type | Description |
---|---|---|
value | MailSensitivity |
setSubject(String value)
public void setSubject(String value)
Gets or sets the subject line
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.lang.String |
setSubjectEncoding(Charset value)
public void setSubjectEncoding(Charset value)
Gets or sets the encoding of subject
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.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:
Parameter | Type | Description |
---|---|---|
value | double | A number of milliseconds. |
setTo(MailAddressCollection value)
public void setTo(MailAddressCollection value)
Gets or sets the address collection that contains the recipients of message
Parameters:
Parameter | Type | Description |
---|---|---|
value | MailAddressCollection |
setXMailer(String value)
public void setXMailer(String value)
Gets or sets the X-Mailer the software that created the e-mail message
Parameters:
Parameter | Type | Description |
---|---|---|
value | java.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:
Parameter | Type | Description |
---|---|---|
stream | java.io.InputStream | A 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:
Parameter | Type | Description |
---|---|---|
fileName | java.lang.String | A 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:
Parameter | Type | Description |
---|---|---|
arg0 | long |
wait(long arg0, int arg1)
public final void wait(long arg0, int arg1)
Parameters:
Parameter | Type | Description |
---|---|---|
arg0 | long | |
arg1 | int |