Class SmtpMessage

java.lang.Object
ch.astorm.smtp4j.core.SmtpMessage

public class SmtpMessage extends Object
Represents an SMTP message.
  • Constructor Details

    • SmtpMessage

      public SmtpMessage(String from, List<String> recipients, jakarta.mail.internet.MimeMessage mimeMessage, String rawMimeContent, List<SmtpExchange> exchanges)
      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.
      exchanges - The raw SMTP exchanges.
  • Method Details

    • getSourceFrom

      public 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:
    • getSourceRecipients

      public List<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:
    • getSmtpExchanges

      public List<SmtpExchange> getSmtpExchanges()
      Returns the raw SMTP exchanges to create this message.
      Returns:
      The raw SMTP exchanges.
    • getFrom

      public 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 List<String> getRecipients(jakarta.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 String getSubject()
      Returns the Subject header of the MIME message.
      Returns:
      The Subject header.
    • getBody

      public 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 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 Date getSentDate()
      Returns the sent date.
      Returns:
      The sent date.
    • getMimeMessage

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

      public 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(String from, List<String> recipients, byte[] mimeMessageContent, List<SmtpExchange> exchanges)
      Creates a new SmtpMessage with the specified parameters.
      Parameters:
      from - The source From parameter value.
      recipients - The source Rcpt parameter values.
      mimeMessageContent - The MimeMessage content.
      exchanges - The raw SMTP exchanges of this message.
      Returns:
      A new SmtpMessage instance.