com.aspose.email
Class MailMessage

java.lang.Object
  extended by com.aspose.email.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. 
 MailMessage deepClone()
           Clones this instance
 void dispose()
           Releases all resources used by the MailMessage
 AlternateViewCollection getAlternateViews()
           Gets the collection of alternate views of message
 AttachmentCollection getAttachments()
           Gets the collection of attachments of message
 MailAddressCollection getBcc()
           Gets or sets the address collection that contains the BCC recipients of message
 String getBody()
           Gets or sets the message body
 Charset getBodyEncoding()
           
 int getBodyType()
           Gets the type of the body.
 Collection getCc()
           Gets CC recipients
 MailAddressCollection getCC()
           Gets or sets the address collection that contains the CC recipients
 Date getDate()
           
 int getDeliveryNotificationOptions()
           Gets or sets the delivery notifications
 MailAddress getFrom()
           Gets or sets the from address
 HeaderCollection getHeaders()
           Gets headers collection of message
 String getHtmlBody()
           Gets or sets html body
 LinkedResourceCollection getLinkedResources()
           Gets the collection of linked resources of message
 String getMessageId()
           Gets or sets the message id
 Charset getPreferredTextEncoding()
           
 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
 MailPriority getPriority()
           Gets or sets the priority of message
 MailAddress getReplyTo()
          Deprecated. 
 MailAddressCollection getReplyToList()
           Gets or sets the list of addresses to reply to for the mail message
 MailAddress getReversePath()
           Gets or sets ReversePath address
 MailAddress getSender()
           Gets or sets sender address
 MailSensitivity getSensitivity()
           Gets or sets the sensitivity of message
 String getSubject()
           Gets or sets the subject line
 Charset getSubjectEncoding()
           
 String getTextBody()
           Gets or sets plain text body
 MailAddressCollection getTo()
           Gets or sets the address collection that contains the recipients of message
 boolean getWriteHeaderToMht()
          Deprecated. 
 boolean getWriteOutlineAttachmentsToMht()
          Deprecated. 
 String getXMailer()
           Gets or sets the X-Mailer the software that created the e-mail message
 void importMessage(InputStream stream)
           
 boolean isBodyHtml()
           Gets or sets a value indicating whether the message body is in Html
 void isBodyHtml(boolean value)
           
 boolean isReadOnly()
           Gets a value indicating whether the message is read only
 boolean isSigned()
           Gets a value indicating whether the message is signed
 Iterator<MailMessage> iterator()
           
static MailMessage load(InputStream stream)
           
static MailMessage load(InputStream stream, int mode)
           
static MailMessage load(InputStream stream, MessageFormat format)
           
static MailMessage load(String fileName)
           Load message from file
static MailMessage load(String fileName, int mode)
           Load message from file
static MailMessage load(String fileName, MessageFormat format)
           Load message from stream
static MailMessage loadFromTnef(InputStream stream)
           
static MailMessage loadFromTnef(String fileName)
           Loads message from Transport Neutral Encapsulation Format (TNEF) data structure
 void save(OutputStream stream)
           
 void save(OutputStream stream, int mode)
           
 void save(OutputStream stream, MailMessageSaveType savetype)
           
 void save(OutputStream stream, MailMessageSaveType savetype, int saveOptions)
           
 void save(OutputStream stream, MessageFormat format)
           
 void save(OutputStream stream, MessageFormat format, int saveOptions)
           
 void save(String fileName)
           Save message as a file
 void save(String fileName, int mode)
           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, int saveOptions)
           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, int saveOptions)
           Message saving into a file into one of the supported formats
 void setBcc(MailAddressCollection value)
           
 void setBody(String value)
           
 void setBodyEncoding(Charset value)
           
 void setCC(MailAddressCollection value)
           
 void setDate(Date value)
           
 void setDeliveryNotificationOptions(int value)
           
 void setFrom(IMailAddress value)
           Gets or sets a from address
 void setFrom(MailAddress value)
           
 void setHtmlBody(String value)
           
 void setMessageId(String value)
           
 void setPreferredTextEncoding(Charset value)
           
 void setPreferredTextEncodingInternal(com.aspose.email.ms.System.Text.Encoding value)
           
 void setPreserveOriginalDates(boolean value)
           
 void setPriority(MailPriority value)
           
 void setReplyTo(MailAddress value)
          Deprecated. 
 void setReplyToList(MailAddressCollection value)
           
 void setReversePath(MailAddress value)
           
 void setSender(MailAddress value)
           
 void setSensitivity(MailSensitivity value)
           
 void setSubject(String value)
           
 void setSubjectEncoding(Charset value)
           
 void setTextBody(String value)
           
 void setTo(MailAddressCollection value)
           
 void setWriteHeaderToMht(boolean value)
          Deprecated. 
 void setWriteOutlineAttachmentsToMht(boolean value)
          Deprecated. 
 void setXMailer(String value)
           
static EmlValidationErrorCollection validateMessage(InputStream stream)
           
static EmlValidationErrorCollection validateMessage(String fileName)
           Validate eml message for corresponding to mime specification.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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


getPreferredTextEncoding

public Charset getPreferredTextEncoding()
Specified by:
getPreferredTextEncoding in interface IPreferredTextEncodingProvider

setPreferredTextEncodingInternal

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

setPreferredTextEncoding

public void setPreferredTextEncoding(Charset value)
Specified by:
setPreferredTextEncoding in interface IPreferredTextEncodingProvider

getFrom

public MailAddress getFrom()

Gets or sets the from address

Specified by:
getFrom in interface IMessage

setFrom

public void setFrom(MailAddress value)

getSender

public MailAddress getSender()

Gets or sets sender address


setSender

public void setSender(MailAddress value)

getReversePath

public MailAddress getReversePath()

Gets or sets ReversePath address


setReversePath

public void setReversePath(MailAddress value)

getReplyTo

@Deprecated
public MailAddress getReplyTo()
Deprecated. 

Gets or sets the ReplyTo address


setReplyTo

@Deprecated
public void setReplyTo(MailAddress value)
Deprecated. 


getReplyToList

public MailAddressCollection getReplyToList()

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


setReplyToList

public void setReplyToList(MailAddressCollection value)

getTo

public MailAddressCollection getTo()

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

Specified by:
getTo in interface IMessage

setTo

public void setTo(MailAddressCollection value)

getBcc

public MailAddressCollection getBcc()

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

Specified by:
getBcc in interface IMessage

setBcc

public void setBcc(MailAddressCollection value)

getCC

public MailAddressCollection getCC()

Gets or sets the address collection that contains the CC recipients


setCC

public void setCC(MailAddressCollection value)

getPriority

public MailPriority getPriority()

Gets or sets the priority of message


setPriority

public void setPriority(MailPriority value)

getSensitivity

public MailSensitivity getSensitivity()

Gets or sets the sensitivity of message


setSensitivity

public void setSensitivity(MailSensitivity value)

getDeliveryNotificationOptions

public int getDeliveryNotificationOptions()

Gets or sets the delivery notifications


setDeliveryNotificationOptions

public void setDeliveryNotificationOptions(int value)

getSubject

public String getSubject()

Gets or sets the subject line

Specified by:
getSubject in interface IMessage

setSubject

public void setSubject(String value)
Specified by:
setSubject in interface IMessage

getDate

public Date getDate()
Specified by:
getDate in interface IMessage

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)

getHtmlBody

public String getHtmlBody()

Gets or sets html body

Specified by:
getHtmlBody in interface IMessage

setHtmlBody

public void setHtmlBody(String value)
Specified by:
setHtmlBody in interface IMessage

getBody

public String getBody()

Gets or sets the message body

Specified by:
getBody in interface IMessage

setBody

public void setBody(String value)
Specified by:
setBody 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)

getAttachments

public AttachmentCollection getAttachments()

Gets the collection of attachments of message

Specified by:
getAttachments in interface IMessage

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. 


getCc

public Collection getCc()

Gets CC recipients

Specified by:
getCc in interface IMessage

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(InputStream stream)

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(InputStream stream,
                               int mode)

load

public static MailMessage load(InputStream stream,
                               MessageFormat format)

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(InputStream stream)

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.

validateMessage

public static EmlValidationErrorCollection validateMessage(InputStream stream)

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.


save

public void save(OutputStream stream,
                 int mode)

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(OutputStream stream)
Specified by:
save in interface IMessage

save

public void save(OutputStream stream,
                 MessageFormat format)

save

public void save(OutputStream stream,
                 MessageFormat format,
                 int saveOptions)

save

public void save(OutputStream stream,
                 MailMessageSaveType savetype)
Specified by:
save in interface IMessage

save

public void save(OutputStream stream,
                 MailMessageSaveType savetype,
                 int saveOptions)

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

addCalendar

@Deprecated
public void addCalendar(Calendar calendar)
Deprecated. 


dispose

public void dispose()

Releases all resources used by the MailMessage

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

iterator

public Iterator<MailMessage> iterator()
Specified by:
iterator in interface Iterable<MailMessage>


Copyright (c) 2008-2012 Aspose Pty Ltd. All Rights Reserved.