com.aspose.email

Interfaces

Classes

Enums

Exceptions

com.aspose.email

Class MapiMessage

  • All Implemented Interfaces:
    IMapiMessageItem, com.aspose.ms.System.IDisposable


    public final class MapiMessage
    extends MapiMessageItemBase

    Represents an Outlook Message format document that can be parsed.


    The following exmaple demonstrates how to read Outlook Message files.

    [Java]

      //Open Outlook Message files
      MapiMessage msg = MapiMessage.fromFile("outlookmessage.msg");
    
      //read subject
      System.out.print("Subject:" + msg.getSubject());
    
      //sender name
      System.out.print("From:" + msg.getSenderName());
    
      //message body
      System.out.print("Body:" + msg.getBody());
    
      //Attachments
      for(MapiAttachment att : msg.getAttachments())
      {
          System.out.print("Attachment Name:"+att.getFileName());
          att.save(att.getFileName());
      }
      


    Instances of the MapiMessage class are used to represent Microsoft Outlook Message document files that are parsed by MapiMessageReader class. To access the sender, recipient, and contents of an e-mail message, use the associated properties of the MapiMessage class.
    • Constructor Detail

      • MapiMessage

        public MapiMessage()

        Initializes a new instance of the MapiMessage class.

      • MapiMessage

        public MapiMessage(int format)

        Initializes a new instance of the MapiMessage class.

        Parameters:
        format - Defines whether to use Unicode or ASCII encoding for this message.
      • MapiMessage

        public MapiMessage(String from,
                   String to,
                   String subject,
                   String body,
                   int format)

        Initializes a new instance of the MapiMessage class.

        Parameters:
        from - The From address.
        to - The addresses of recipients. Note, that addresses are separated by semicolon.
        subject - The message subject.
        body - The message body.
        format - Defines whether to use Unicode or ASCII encoding for this message.
        Throws:
        com.aspose.ms.System.ArgumentNullException - Is being thrown if address of recipient is null or empty.
        com.aspose.ms.System.ArgumentException - Is being thrown if sender or recipient address is not in a recognized format.
        com.aspose.ms.System.ComponentModel.InvalidEnumArgumentException - Is being thrown if format parameter is not a valid enumeration member.
      • MapiMessage

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

        Initializes a new instance of the MapiMessage class.

        Parameters:
        from - The From address.
        to - The addresses of recipients. Note, that addresses are separated by semicolon.
        subject - The message subject.
        body - The message body.
        Throws:
        com.aspose.ms.System.ArgumentNullException - throws if address of recipient is null or empty.
        com.aspose.ms.System.ArgumentException - throws if sender or recipient address is not in a recognized format.
    • Method Detail

      • getReplyTo

        public final String getReplyTo()

        Gets or sets the reply to names.

        Throws:
        com.aspose.ms.System.ArgumentNullException - throws if reply to address is null.
        com.aspose.ms.System.ArgumentException - throws if reply to address is not in a recognized format. Value: The reply to names.


        Gets or sets the list of ReplyTo addresses separated by semicolon.
      • setReplyTo

        public final void setReplyTo(String value)

        Gets or sets the reply to names.

        Throws:
        com.aspose.ms.System.ArgumentNullException - throws if reply to address is null.
        com.aspose.ms.System.ArgumentException - throws if reply to address is not in a recognized format. Value: The reply to names.


        Gets or sets the list of ReplyTo addresses separated by semicolon.
      • getNormalizedSubject

        public final String getNormalizedSubject()

        Gets normalized subject of the message.

        Value: The string that represents normalized subject.
      • getDisplayTo

        public final String getDisplayTo()

        Gets a list of the display names of the primary (To) message recipients, separated by semicolons (;).

        Value: The string that represents display to.
      • getDisplayNamePrefix

        public final String getDisplayNamePrefix()

        Gets a prefix of the display name.

        Value: The string that represents display name prefix.
      • getDisplayName

        public final String getDisplayName()

        Gets the display name for the message.

        Value: The string that represents display name.
      • getDisplayCc

        public final String getDisplayCc()

        Gets a list of the display names of any carbon copy (CC) message recipients, separated by semicolons (;).

        Value: The string that represents display cc.
      • getDisplayBcc

        public final String getDisplayBcc()

        Gets a list of the display names of any blind carbon copy (BCC) message recipients, separated by semicolons (;).

        Value: The string that represents display bcc.
      • getSenderEmailAddress

        public final String getSenderEmailAddress()

        Gets or sets the message sender's e-mail address.

        Throws:
        com.aspose.ms.System.ArgumentException - throws if sender address is not in a recognized format. Value: The string that represents sender email address.


        When setting a value, the values of PR_SENDER_SEARCH_KEY and PR_SENDER_ENTRYID properties are updated as well. When setting a null value or empty string, the values of properties are set null.
      • setSenderEmailAddress

        public final void setSenderEmailAddress(String value)

        Gets or sets the message sender's e-mail address.

        Throws:
        com.aspose.ms.System.ArgumentException - throws if sender address is not in a recognized format. Value: The string that represents sender email address.


        When setting a value, the values of PR_SENDER_SEARCH_KEY and PR_SENDER_ENTRYID properties are updated as well. When setting a null value or empty string, the values of properties are set null.
      • getSenderSmtpAddress

        public final String getSenderSmtpAddress()

        Gets or sets the message sender's e-mail address.

        Throws:
        com.aspose.ms.System.ArgumentException - throws if sender address is not in a recognized format. Value: The string that represents sender email address.


        When setting a value, the values of PR_SENDER_SEARCH_KEY and PR_SENDER_ENTRYID properties are updated as well. When setting a null value or empty string, the values of properties are set null.
      • setSenderSmtpAddress

        public final void setSenderSmtpAddress(String value)

        Gets or sets the message sender's e-mail address.

        Throws:
        com.aspose.ms.System.ArgumentException - throws if sender address is not in a recognized format. Value: The string that represents sender email address.


        When setting a value, the values of PR_SENDER_SEARCH_KEY and PR_SENDER_ENTRYID properties are updated as well. When setting a null value or empty string, the values of properties are set null.
      • getSenderAddressType

        public final String getSenderAddressType()

        Gets the message sender's e-mail address type.

        Value: The string that represents sender address type.
      • getSenderName

        public final String getSenderName()

        Gets or sets the message sender's display name.

        Value: The the string that represents sender name.


        When setting a null value or empty string, the values of the property get the value equal to SenderEmailAddress.
      • setSenderName

        public final void setSenderName(String value)

        Gets or sets the message sender's display name.

        Value: The the string that represents sender name.


        When setting a null value or empty string, the values of the property get the value equal to SenderEmailAddress.
      • getTransportMessageHeaders

        public final String getTransportMessageHeaders()

        Gets the transport-specific message envelope information.

        Value: The string that represents transport message headers.
      • getInternetMessageId

        public final String getInternetMessageId()

        Gets the message id of the message.

        Value: The string that represents internet message id.
      • getConversationTopic

        public final String getConversationTopic()

        Gets the topic of the first message in a conversation thread.

        Value: The string that represens conversation topic.
      • getSentRepresentingEmailAddress

        public final String getSentRepresentingEmailAddress()

        Gets or sets the e-mail address for the messaging user represented by the sender.

        Throws:
        com.aspose.ms.System.ArgumentException - throws if email address is not in a recognized format. Value: The string that represents sent representing email address.


        When setting a value, the values of PR_SENT_REPRESENTING_SEARCH_KEY and PR_SENT_REPRESENTING_ENTRYID properties are updated as well. When setting a null value or empty string, the values of the property are set null.
      • setSentRepresentingEmailAddress

        public final void setSentRepresentingEmailAddress(String value)

        Gets or sets the e-mail address for the messaging user represented by the sender.

        Throws:
        com.aspose.ms.System.ArgumentException - throws if email address is not in a recognized format. Value: The string that represents sent representing email address.


        When setting a value, the values of PR_SENT_REPRESENTING_SEARCH_KEY and PR_SENT_REPRESENTING_ENTRYID properties are updated as well. When setting a null value or empty string, the values of the property are set null.
      • getSentRepresentingSmtpAddress

        public final String getSentRepresentingSmtpAddress()

        Gets or sets the e-mail address for the messaging user represented by the sender.

        Value: The string that represents sent representing email address.
      • getSentRepresentingAddressType

        public final String getSentRepresentingAddressType()

        Gets the address type for the messaging user represented by the sender.

        Value: The string that represents sent representing address type.
      • getSentRepresentingName

        public final String getSentRepresentingName()

        Gets or sets the display name for the messaging user represented by the sender.

        Value: The string that represents sent representing name.


        When setting a null value or empty string, the values of the property are set in SentRepresentingEmailAddress.
      • setSentRepresentingName

        public final void setSentRepresentingName(String value)

        Gets or sets the display name for the messaging user represented by the sender.

        Value: The string that represents sent representing name.


        When setting a null value or empty string, the values of the property are set in SentRepresentingEmailAddress.
      • getClientSubmitTime

        public final Date getClientSubmitTime()

        Gets or sets the date and time the message sender submitted a message.

        Value: The DateTime that represents client submit time.


        If the property was not available, DateTime.MinValue is returned.
      • setClientSubmitTime

        public final void setClientSubmitTime(Date value)

        Gets or sets the date and time the message sender submitted a message.

        Value: The DateTime that represents client submit time.


        If the property was not available, DateTime.MinValue is returned.
      • getDeliveryTime

        public final Date getDeliveryTime()

        Gets or sets the date and time a message was delivered.

        Value: The DateTime that represents delivery time.


        If the property was not available, DateTime.MinValue is returned.
      • setDeliveryTime

        public final void setDeliveryTime(Date value)

        Gets or sets the date and time a message was delivered.

        Value: The DateTime that represents delivery time.


        If the property was not available, DateTime.MinValue is returned.
      • getHeaders

        public final HeaderCollection getHeaders()

        Gets the transport message headers

      • setHeaders

        public final void setHeaders(HeaderCollection value)

        Gets the transport message headers

      • getFlags

        public final long getFlags()

        Gets the message flags.

        Value: The message flags.
      • getReadReceiptRequested

        public final boolean getReadReceiptRequested()

        Gets or sets a value indicating whether the read receipt is requested.

        Value: true if the read receipt is requested; otherwise, false.
      • setReadReceiptRequested

        public final void setReadReceiptRequested(boolean value)

        Gets or sets a value indicating whether the read receipt is requested.

        Value: true if the read receipt is requested; otherwise, false.
      • getMessageFormat

        public final int getMessageFormat()

        Gets the outlook message format.

        Value: The outlook message format.
      • load

        public static MapiMessage load(InputStream stream,
                       LoadOptions options)

        Loads message from stream with additional options.

        Parameters:
        stream - Source streamInputStream.
        options - Additional options LoadOptions.
        Returns:
        Throws:
        FormatNotSupportedException - Passed message format is not supported.
        com.aspose.ms.System.ArgumentNullException - Stream should not be null or empty.
        com.aspose.ms.System.NotSupportedException - Stream does not support reading.
      • load

        public static MapiMessage load(String fileName,
                       LoadOptions options)

        Loads message from file with additional options.

        Parameters:
        fileName - Source file pathString.
        options - Additional options LoadOptions.
        Returns:
        Throws:
        com.aspose.ms.System.ArgumentNullException - File name should not be null or empty.
        com.aspose.ms.System.NotSupportedException - Stream does not support reading.
        FormatNotSupportedException - Passed message format is not supported.
      • fromFile

        public static MapiMessage fromFile(String path)

        Create an instance of MapiMessage from the specified file.

        Parameters:
        path - The name of the file to be loaded.
        Returns:
        Returns a MapiMessage instance which is loaded from the specified file.
      • fromStream

        public static MapiMessage fromStream(InputStream stream)

        Create an instance of MapiMessage from the specified stream.

        Parameters:
        stream - The stream to be loaded.
        Returns:
        Returns a MapiMessage instance which is loaded from the specified stream.
      • fromProperties

        public static MapiMessage fromProperties(MapiPropertyCollection properties)

        Creates an instance of MapiMessage from a collection of Mapi properties.

        Parameters:
        properties - A collection of MapiProperty.
        Returns:
        Returns a MapiMessage instance which is loaded from the specified properties.
      • fromMailMessage

        public static MapiMessage fromMailMessage(String fileName)

        Creates an instance of MapiMessage from the MailMessage.

        Parameters:
        fileName - The file name of MailMessage.
        Returns:
        Returns a MapiMessage instance which is loaded from the MailMessage.
      • fromMailMessage

        public static MapiMessage fromMailMessage(MailMessage message)

        Creates an instance of MapiMessage from the MailMessage.

        Parameters:
        message - The MailMessage.
        Returns:
        Returns a MapiMessage instance which is loaded from the MailMessage.
      • removeAttachments

        public static MapiAttachmentCollection removeAttachments(String path)

        Removes all of the attachments from the specified Outlook Message files.


        The following exmaple demonstrates how to destroy attachments in Outlook Message files.

        [Java]

             //Remove attachments from Outlook Message files
             MapiAttachmentCollection attachments = MapiMessage.removeAttachments("outlookmessage.msg");
        
             //Attachments
             for(MapiAttachment att : attachments)
             {
                System.out.print("Attachment Name:"+att.getFileName());
                att.save(att.getFileName());
             }
         
        Parameters:
        path - The name of the Outlook Message file.
        Returns:
        The attachments collection.
      • destroyAttachments

        public static void destroyAttachments(String path)

        Destroies the attachments in the specified Outlook Message files. DestroyAttachments will ignore the attachment parsing.


        The following exmaple demonstrates how to destroy attachments in Outlook Message files.

        [Java]

             //Destroy attachments from Outlook Message files
             MapiMessage.destroyAttachment("outlookmessage.msg");
         
        Parameters:
        path - The name of the Outlook Message file.
      • loadFromTnef

        public static MapiMessage loadFromTnef(InputStream stream)

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

        Parameters:
        stream - A stream representing message data in TNEF format
        Returns:
        A read MapiMessage
        Throws:
        com.aspose.ms.System.ArgumentNullException - stream is null
        com.aspose.ms.System.NotSupportedException - stream does not support reading
      • loadFromTnef

        public static MapiMessage 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 MapiMessage
        Throws:
        com.aspose.ms.System.ArgumentException - fileName is null or empty
      • isMsgFormat

        public static boolean isMsgFormat(String fileName)

        Determines whether the specified file has a MSG format.

        Parameters:
        fileName - Name of the file.
        Returns:
        true if the file is represented in MSG format; otherwise, false.
      • isMsgFormat

        public static boolean isMsgFormat(InputStream stream)

        Determines whether the specified stream has a MSG format.

        Parameters:
        stream - The message stream.
        Returns:
        true if the stream is represented in MSG format]; otherwise, false.
      • setStringPropertyValue

        public final void setStringPropertyValue(long tag,
                                  String value)

        Sets the string property value.

        Parameters:
        tag - The property tag.
        value - The property value.
      • addCustomProperty

        public final void addCustomProperty(MapiProperty property,
                             String stringNameId)

        Adds the custom property.

        Parameters:
        property - The propertyMapiProperty.
        stringNameId - The name of propertyString.
        Throws:
        com.aspose.ms.System.ArgumentNullException - If property is null.
        com.aspose.ms.System.ArgumentException - If property data is null.
        com.aspose.ms.System.NotSupportedException - If data type is not supported yet.
      • addCustomProperty

        public final void addCustomProperty(int type,
                             byte[] data,
                             String stringNameId)

        Adds the custom property.

        Parameters:
        type - Type of MapiPropertyMapiPropertyType
        data - MapiProperty data.byte
        stringNameId - The name of propertyString.
        Throws:
        com.aspose.ms.System.ArgumentException - If property data is null.
        com.aspose.ms.System.NotSupportedException - If data type is not supported yet.
      • toMapiMessageItem

        public final IMapiMessageItem toMapiMessageItem()

        Convert MapiMessage to IMapiMessageItem object in dependence with MessageClass.

        Returns:
        The IMapiMessageItem interface.
        Throws:
        com.aspose.ms.System.NotSupportedException - Thrown when MessageClass doesn't belong to IPM.Note, IPM.StickyNote, IPM.Contact, IPM.Activity, IPM.Appointment, IPM.Schedule.meeting, IPM.Task.


        Note, that the following message classes are supported by now: IPM.Note, IPM.StickyNote, IPM.Contact, IPM.Activity, IPM.Appointment, IPM.Schedule.meeting, IPM.Task. If MapiMessage has another class, different from these ones, then NotSupportedException is thrown. If MessageClass is IPM.Note, then MapiMessage copy is returned.
      • toMailMessage

        public final MailMessage toMailMessage(MailConversionOptions options)

        Creates an instance of MailMessage from this MapiMessage.

        Parameters:
        options - Allows to specify additional options when converting from MapiMessage to MailMessage.
        Returns:
        Returns a MailMessage instance which is loaded from this MapiMessage.
      • save

        public final void save(String fileName,
                SaveOptions options)

        Saves message as a file with additional options.

        Parameters:
        fileName - Stream into which message is saved.
        options - Additional options for savingSaveOptions.
      • save

        public final void save(OutputStream stream,
                SaveOptions options)

        Saves message as a stream with additional options.

        Parameters:
        stream - Stream into which message is saved.
        options - Additional options for savingSaveOptions.
      • saveAsTnef

        public final void saveAsTnef(OutputStream stream)

        Save message in TNEF format.

        Parameters:
        stream - The stream where a message will be saved to.
      • saveAsTnef

        public final void saveAsTnef(String fileName)

        Save message in TNEF format.

        Parameters:
        fileName - Name of the file where a message will be saved to.
      • save

        public final void save(String fileName)

        Saves to the specified file as Msg.

        Parameters:
        fileName - Name of the file.
      • saveAsTemplate

        public final void saveAsTemplate(String fileName)

        Saves to the specified file as Outlook File Template(OFT format).

        Parameters:
        fileName - Name of the file.
      • save

        public final void save(OutputStream stream)

        Saves to the specified stream as Msg.

        Parameters:
        stream - The stream.
      • saveAsTemplate

        public final void saveAsTemplate(OutputStream stream)

        Saves to the specified stream as Outlook File Template(OFT format).

        Parameters:
        stream - The stream.
      • checkBounced

        public final BounceResult checkBounced()

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

        Returns:
        Result of checkingBounceResult.
      • deepClone

        public final MapiMessage deepClone()

        Creates a new object that is a copy of the current instance.

        Returns:
        A new object that is a copy of this instance.
      • setProperty

        public void setProperty(MapiAttachment value,
                       long signed,
                       long key)

        Sets the attachment.

        Parameters:
        value - The property value.
        signed - The value, that indicates that the property is signed.
        key - The property tag.
      • setProperty

        public void setProperty(MapiRecipient value,
                       long signed,
                       long key)

        Sets the recipient.

        Parameters:
        value - The property value.
        signed - The value, that indicates that the property is signed.
        key - The property tag.