Class SmtpMessage


  • public class SmtpMessage
    extends java.lang.Object
    Represents an SMTP message.
    • Constructor Summary

      Constructors 
      Constructor Description
      SmtpMessage​(java.lang.String from, java.util.List<java.lang.String> recipients, javax.mail.internet.MimeMessage mimeMessage, java.lang.String rawMimeContent)
      Creates a new SmtpMessage with the specified parameters.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static SmtpMessage create​(java.lang.String from, java.util.List<java.lang.String> recipients, java.lang.String mimeMessageStr)
      Creates a new SmtpMessage with the specified parameters.
      java.util.List<SmtpAttachment> getAttachments()
      Returns the attachments of the MIME message.
      java.lang.String getBody()
      Returns the content of the MIME message.
      java.lang.String getFrom()
      Returns the From header of the MIME message.
      javax.mail.internet.MimeMessage getMimeMessage()
      Returns the MimeMessage parsed from the content.
      java.lang.String getRawMimeContent()
      Returns the internal raw content received by the SMTP server to parse as MimeMessage.
      java.util.List<java.lang.String> getRecipients​(javax.mail.Message.RecipientType type)
      Returns all the recipients of the given type.
      java.util.Date getSentDate()
      Returns the sent date.
      java.lang.String getSourceFrom()
      Returns the From parameter specified during the protocol exchange.
      java.util.List<java.lang.String> getSourceRecipients()
      Returns the list of To parameters specified during the protocol exchange.
      java.lang.String getSubject()
      Returns the Subject header of the MIME message.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SmtpMessage

        public SmtpMessage​(java.lang.String from,
                           java.util.List<java.lang.String> recipients,
                           javax.mail.internet.MimeMessage mimeMessage,
                           java.lang.String rawMimeContent)
        Creates a new SmtpMessage with the specified parameters.
        Parameters:
        from - The source From parameter value.
        recipients - The source Rcpt parameter values.
        mimeMessage - The parsed MimeMessage.
        rawMimeContent - The raw MIME content of mimeMessage.
    • Method Detail

      • getSourceFrom

        public java.lang.String getSourceFrom()
        Returns the From parameter specified during the protocol exchange. This value will contain only the email (info@mydomain.com).
        Returns:
        The MAIL FROM: value.
        See Also:
        SmtpCommand.Type.MAIL_FROM
      • getSourceRecipients

        public java.util.List<java.lang.String> getSourceRecipients()
        Returns the list of To parameters specified during the protocol exchange. The values will contain only the email (info@mydomain.com).

        Note that all recipients (including Message.RecipientType.BCC) will be present in this list.

        Returns:
        The RCPT TO: values.
        See Also:
        SmtpCommand.Type.RECIPIENT
      • getFrom

        public java.lang.String getFrom()
        Returns the From header of the MIME message. This value can be composed, for instance: Cédric <info@mydomain.com>.
        Returns:
        The From header.
      • getRecipients

        public java.util.List<java.lang.String> getRecipients​(javax.mail.Message.RecipientType type)
        Returns all the recipients of the given type. Those values can be composed, for instance: Cédric <info@mydomain.com>.

        The Message.RecipientType.BCC will always yield an empty list.

        Parameters:
        type - The type.
        Returns:
        A list of recipients or an empty list if there is none.
      • getSubject

        public java.lang.String getSubject()
        Returns the Subject header of the MIME message.
        Returns:
        The Subject header.
      • getBody

        public java.lang.String getBody()
        Returns the content of the MIME message. If the underlying MimeMessage is a MimeMultipart, then all the parts without a filename will be concatenated together (separated by SmtpProtocolConstants.CRLF and returned as the body. If there is none, then null will be returned.
        Returns:
        The content or null.
      • getAttachments

        public java.util.List<SmtpAttachment> getAttachments()
        Returns the attachments of the MIME message. If the underlying MimeMessage is not MimeMultipart an empty list will be returned.

        Note that only parts with a name will be considered as attachment.

        Returns:
        A list of attachments.
      • getSentDate

        public java.util.Date getSentDate()
        Returns the sent date.
        Returns:
        The sent date.
      • getMimeMessage

        public javax.mail.internet.MimeMessage getMimeMessage()
        Returns the MimeMessage parsed from the content.
        Returns:
        the MimeMessage.
      • getRawMimeContent

        public java.lang.String getRawMimeContent()
        Returns the internal raw content received by the SMTP server to parse as MimeMessage.
        Returns:
        The raw content.
      • create

        public static SmtpMessage create​(java.lang.String from,
                                         java.util.List<java.lang.String> recipients,
                                         java.lang.String mimeMessageStr)
        Creates a new SmtpMessage with the specified parameters.
        Parameters:
        from - The source From parameter value.
        recipients - The source Rcpt parameter values.
        mimeMessageStr - The MimeMessage content.
        Returns:
        A new SmtpMessage instance.