com.aspose.email

com.aspose.email

Class MailMessage

All Implemented Interfaces:
IMessage, IPreferredTextEncodingProvider, com.aspose.email.ms.System.IDisposable, Iterable<MailMessage>
public class MailMessage
extends Object
implements com.aspose.email.ms.System.IDisposable, IPreferredTextEncodingProvider, IMessage, Iterable<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 Summary
MailMessage()
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
 
Method Summary
void
addAlternateView(AlternateView view)
Add an alternate view to message
void
addAttachment(Attachment attachment)
Add an attachment to message
void
addCalendar(Calendar calendar)
Deprecated. 
deepClone()
Clones this instance
void
dispose()
Releases all resources used by the MailMessage
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 message body
int
getBodyType()
Gets the type of the body.
getCc()
Gets CC recipients
getCC()
Gets or sets the address collection that contains the CC recipients
int
getDeliveryNotificationOptions()
Gets or sets the delivery notifications
getFrom()
Gets or sets the from address
getHeaders()
Gets headers collection of message
getHtmlBody()
Gets or sets html body
getLinkedResources()
Gets the collection of linked resources of message
getMessageId()
Gets or sets the message id
com.aspose.email.ms.System.Text.Encoding
getPreferredTextEncodingInternal()
Gets or sets preferred encoding for all text properties
boolean
getPreserveOriginalDates()
Gets or sets a value indicating whether it is necessary to generate new saving and modification dates when saving a message
getPriority()
Gets or sets the priority of message
getReplyTo()
Deprecated. 
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
getTextBody()
Gets or sets plain text body
com.aspose.email.ms.System.TimeSpan
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
boolean
getWriteHeaderToMht()
Deprecated. 
boolean
getXMailer()
Gets or sets the X-Mailer the software that created the e-mail message
void
boolean
isBodyHtml()
Gets or sets a value indicating whether the message body is in Html
void
isBodyHtml(booleanvalue)
boolean
isReadOnly()
Gets a value indicating whether the message is read only
boolean
isSigned()
Gets a value indicating whether the message is signed
load(InputStream stream)
load(InputStream stream, intmode)
load(InputStream stream, MessageFormat format)
load(String fileName)
Load message from file
load(String fileName, intmode)
Load message from file
load(String fileName, MessageFormat format)
Load message from stream
loadFromTnef(String fileName)
Loads message from Transport Neutral Encapsulation Format (TNEF) data structure
void
recomposeTnefContent()
Composes the TNEF content.
void
save(OutputStream stream)
void
save(OutputStream stream, intmode)
void
void
save(OutputStream stream, MailMessageSaveType savetype, intsaveOptions)
void
save(OutputStream stream, MessageFormat format)
void
save(OutputStream stream, MessageFormat format, intsaveOptions)
void
save(String fileName)
Save message as a file
void
save(String fileName, intmode)
Save message as a file
void
save(String fileName, MailMessageSaveType savetype)
Message saving into a file into one of the supported formats
void
save(String fileName, MailMessageSaveType savetype, intsaveOptions)
Message saving into a file into one of the supported formats
void
save(String fileName, MessageFormat format)
Message saving into a file into one of the supported formats
void
save(String fileName, MessageFormat format, intsaveOptions)
Message saving into a file into one of the supported formats
void
void
setBody(String value)
void
void
void
setDate(Date value)
void
void
setFrom(IMailAddress value)
Gets or sets a from address
void
void
void
void
void
setPreferredTextEncodingInternal(com.aspose.email.ms.System.Text.Encodingvalue)
void
void
void
setReplyTo(MailAddress value)
Deprecated. 
void
void
void
void
void
void
void
void
setTimeZoneOffset(com.aspose.email.ms.System.TimeSpanvalue)
void
void
setWriteHeaderToMht(booleanvalue)
Deprecated. 
void
setWriteOutlineAttachmentsToMht(booleanvalue)
Deprecated. 
void
validateMessage(String fileName)
Validate eml message for corresponding to mime specification.
 
Methods inherited from class java.lang.Object
 

    • Constructor Detail

      • MailMessage

        public MailMessage(String from,
                           String to)

        Initializes a new instance of the MailMessage class

        Parameters:
        from - Sender address
        to - Recipient address
      • MailMessage

        public MailMessage()

        Initializes a new instance of the MailMessage class

      • MailMessage

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

        Initializes a new instance of the MailMessage class

        Parameters:
        from - Sender address
        to - Recipient address
        subject - Message subject
        body - Message body
      • MailMessage

        public MailMessage(MailAddress from,
                           MailAddress to)

        Initializes a new instance of the MailMessage class

        Parameters:
        from - Sender address
        to - Recipient address
    • Method Detail

      • getPreferredTextEncodingInternal

        public com.aspose.email.ms.System.Text.Encoding getPreferredTextEncodingInternal()

        Gets or sets preferred encoding for all text properties

      • setPreferredTextEncodingInternal

        public void setPreferredTextEncodingInternal(com.aspose.email.ms.System.Text.Encoding value)
      • getSender

        public MailAddress getSender()

        Gets or sets sender address

      • getReversePath

        public MailAddress getReversePath()

        Gets or sets ReversePath address

      • setReversePath

        public void setReversePath(MailAddress value)
      • getReplyToList

        public MailAddressCollection getReplyToList()

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

      • getCC

        public MailAddressCollection getCC()

        Gets or sets the address collection that contains the CC recipients

      • getPriority

        public MailPriority getPriority()

        Gets or sets the priority of message

      • getSensitivity

        public MailSensitivity getSensitivity()

        Gets or sets the sensitivity of message

      • getDeliveryNotificationOptions

        public int getDeliveryNotificationOptions()

        Gets or sets the delivery notifications

      • setDeliveryNotificationOptions

        public void setDeliveryNotificationOptions(int value)
      • getTimeZoneOffset

        public com.aspose.email.ms.System.TimeSpan 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.

      • setTimeZoneOffset

        public void setTimeZoneOffset(com.aspose.email.ms.System.TimeSpan value)
      • setDate

        public void setDate(Date value)
      • getMessageId

        public String getMessageId()

        Gets or sets the message id

      • setMessageId

        public void setMessageId(String value)
      • getXMailer

        public String getXMailer()

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

      • setXMailer

        public void setXMailer(String value)
      • getSubjectEncoding

        public Charset getSubjectEncoding()
      • setSubjectEncoding

        public void setSubjectEncoding(Charset value)
      • getHeaders

        public HeaderCollection getHeaders()

        Gets headers collection of message

      • getTextBody

        public String getTextBody()

        Gets or sets plain text body

      • setTextBody

        public void setTextBody(String value)
      • getBody

        public String getBody()

        Gets or sets the message body

        Specified by:
        getBody in interface IMessage
      • getBodyEncoding

        public Charset getBodyEncoding()
      • setBodyEncoding

        public void setBodyEncoding(Charset value)
      • isBodyHtml

        public boolean isBodyHtml()

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

      • isBodyHtml

        public void isBodyHtml(boolean value)
      • isSigned

        public boolean isSigned()

        Gets a value indicating whether the message is signed

      • isReadOnly

        public boolean isReadOnly()

        Gets a value indicating whether the message is read only

      • getPreserveOriginalDates

        public boolean getPreserveOriginalDates()

        Gets or sets a value indicating whether it is necessary to generate new saving and modification dates when saving a message

      • setPreserveOriginalDates

        public void setPreserveOriginalDates(boolean value)
      • getLinkedResources

        public LinkedResourceCollection getLinkedResources()

        Gets the collection of linked resources of message

      • getAlternateViews

        public AlternateViewCollection getAlternateViews()

        Gets the collection of alternate views of message

      • getWriteHeaderToMht

        @Deprecated
        public boolean getWriteHeaderToMht()
        Deprecated. 

        Gets or sets a value indicating whether header information should be written if message is being saved in mht format. Default value is true.

        Value: true if header information should be written; otherwise, false.

      • setWriteHeaderToMht

        @Deprecated
        public void setWriteHeaderToMht(boolean value)
        Deprecated. 

      • getBodyType

        public int getBodyType()

        Gets the type of the body.

        Specified by:
        getBodyType in interface IMessage
      • getWriteOutlineAttachmentsToMht

        @Deprecated
        public boolean getWriteOutlineAttachmentsToMht()
        Deprecated. 

        Gets or sets a value indicating whether outline attachments should be written if message is being saved in mht format. Default value is true.

        Value: true if outline attachments should be written; otherwise, false.

      • setWriteOutlineAttachmentsToMht

        @Deprecated
        public void setWriteOutlineAttachmentsToMht(boolean value)
        Deprecated. 

      • setFrom

        public void setFrom(IMailAddress value)

        Gets or sets a from address

        Specified by:
        setFrom in interface IMessage
        Throws:
        com.aspose.email.ms.System.IllegalArgumentException - Incorrect type of value. Expected type is Aspose.Network.Mail.MailAddress
      • load

        public static MailMessage load(String fileName)

        Load message from file

        Parameters:
        fileName - Message file name. The message file must be in eml or msg format.
        Returns:
        E-mail message
      • load

        public static MailMessage load(String fileName,
                                       int mode)

        Load message from file

        Parameters:
        fileName - Message file name (.eml)
        mode - FileCompatibilityMode that defines inner conversions that are necessarily to be done

        If a flag FileCompatibilityMode.PreserveTnefAttachments is set, it means that TNEF attachment shouldn't be decoded if present. If a flag FileCompatibilityMode.AllowCROnly is set, it means that line separators will be replaced by CRLF.

        Returns:
        E-mail message
      • load

        public static MailMessage load(String fileName,
                                       MessageFormat format)

        Load message from stream

        Parameters:
        fileName - Message file name. File must be in one of the suported formats
        format - Message file format
        Returns:
        E-mail message
        Throws:
        com.aspose.email.ms.System.IllegalArgumentException - If fileName is null.
        FormatNotSupportedException - If format is not supported.
      • loadFromTnef

        public static MailMessage loadFromTnef(String fileName)

        Loads message from Transport Neutral Encapsulation Format (TNEF) data structure

        Parameters:
        fileName - Name of file containing message data in TNEF format
        Returns:
        A read MailMessage
        Throws:
        com.aspose.email.ms.System.IllegalArgumentException - fileName is null or empty
      • validateMessage

        public static EmlValidationErrorCollection validateMessage(String fileName)

        Validate eml message for corresponding to mime specification.

        Parameters:
        fileName - A file name (eml).
        Returns:
        A EmlValidationErrorCollection containing the found validation error messages.
        Throws:
        com.aspose.email.ms.System.IllegalArgumentException - fileName is null or empty.
        com.aspose.email.ms.System.IO.FileNotFoundException - The specified fileName doesn't exist.
      • importMessage

        public void importMessage(InputStream stream)
      • deepClone

        public MailMessage deepClone()

        Clones this instance

        Returns:
        MailMessage that is a copy of the current instance
      • save

        public void save(String fileName,
                         int mode)

        Save message as a file

        Parameters:
        fileName - Name of the file
        mode - FileCompatibilityMode that defines inner conversions that are necessarily to be done

        A message is saved in eml format. If a flag FileCompatibilityMode.PreserveTnefAttachments is set, it means that TNEF attachment should be preserved. Note, that now tnef attachment is saved when being loaded a message contains tnef, that is the FileCompatibilityMode.PreserveTnefAttachments flag doesn't allow to create tnef message out of an regular one.

      • recomposeTnefContent

        public 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.

      • save

        public void save(String fileName)

        Save message as a file

        Specified by:
        save in interface IMessage
        Parameters:
        fileName - File name
      • save

        public void save(String fileName,
                         MailMessageSaveType savetype)

        Message saving into a file into one of the supported formats

        Specified by:
        save in interface IMessage
        Parameters:
        fileName - Full file name
        savetype - Format into which message is saved
      • save

        public void save(String fileName,
                         MailMessageSaveType savetype,
                         int saveOptions)

        Message saving into a file into one of the supported formats

        Parameters:
        fileName - Full file name
        savetype - Format into which message is saved
        saveOptions - Save options
      • save

        public void save(String fileName,
                         MessageFormat format)

        Message saving into a file into one of the supported formats

        Parameters:
        fileName - Full file name
        format - Format into which message is saved
      • save

        public void save(String fileName,
                         MessageFormat format,
                         int saveOptions)

        Message saving into a file into one of the supported formats

        Parameters:
        fileName - Full file name
        format - Format into which message is saved
        saveOptions - Save options
      • addAlternateView

        public void addAlternateView(AlternateView view)

        Add an alternate view to message

        Parameters:
        view - Alternate view for adding
      • addAttachment

        public void addAttachment(Attachment attachment)

        Add an attachment to message

        Parameters:
        attachment - Attachment for adding
      • dispose

        public void dispose()

        Releases all resources used by the MailMessage

        Specified by:
        dispose in interface com.aspose.email.ms.System.IDisposable