Package ch.astorm.smtp4j.core
Class SmtpMessage
- java.lang.Object
-
- ch.astorm.smtp4j.core.SmtpMessage
-
public class SmtpMessage extends java.lang.ObjectRepresents an SMTP message.
-
-
Constructor Summary
Constructors Constructor Description SmtpMessage(java.lang.String from, java.util.List<java.lang.String> recipients, jakarta.mail.internet.MimeMessage mimeMessage, java.lang.String rawMimeContent)Creates a newSmtpMessagewith the specified parameters.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static SmtpMessagecreate(java.lang.String from, java.util.List<java.lang.String> recipients, java.lang.String mimeMessageStr)Creates a newSmtpMessagewith the specified parameters.java.util.List<SmtpAttachment>getAttachments()Returns the attachments of the MIME message.java.lang.StringgetBody()Returns the content of the MIME message.java.lang.StringgetFrom()Returns theFromheader of the MIME message.jakarta.mail.internet.MimeMessagegetMimeMessage()Returns theMimeMessageparsed from the content.java.lang.StringgetRawMimeContent()Returns the internal raw content received by the SMTP server to parse asMimeMessage.java.util.List<java.lang.String>getRecipients(jakarta.mail.Message.RecipientType type)Returns all the recipients of the giventype.java.util.DategetSentDate()Returns the sent date.java.lang.StringgetSourceFrom()Returns theFromparameter specified during the protocol exchange.java.util.List<java.lang.String>getSourceRecipients()Returns the list ofToparameters specified during the protocol exchange.java.lang.StringgetSubject()Returns theSubjectheader of the MIME message.
-
-
-
Constructor Detail
-
SmtpMessage
public SmtpMessage(java.lang.String from, java.util.List<java.lang.String> recipients, jakarta.mail.internet.MimeMessage mimeMessage, java.lang.String rawMimeContent)Creates a newSmtpMessagewith the specified parameters.- Parameters:
from- The sourceFromparameter value.recipients- The sourceRcptparameter values.mimeMessage- The parsedMimeMessage.rawMimeContent- The raw MIME content ofmimeMessage.
-
-
Method Detail
-
getSourceFrom
public java.lang.String getSourceFrom()
Returns theFromparameter 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 ofToparameters 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 theFromheader of the MIME message. This value can be composed, for instance:Cédric <info@mydomain.com>.- Returns:
- The
Fromheader.
-
getRecipients
public java.util.List<java.lang.String> getRecipients(jakarta.mail.Message.RecipientType type)
Returns all the recipients of the giventype. Those values can be composed, for instance:Cédric <info@mydomain.com>.The
Message.RecipientType.BCCwill 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 theSubjectheader of the MIME message.- Returns:
- The
Subjectheader.
-
getBody
public java.lang.String getBody()
Returns the content of the MIME message. If the underlyingMimeMessageis aMimeMultipart, then all the parts without a filename will be concatenated together (separated bySmtpProtocolConstants.CRLFand 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 underlyingMimeMessageis notMimeMultipartan 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 jakarta.mail.internet.MimeMessage getMimeMessage()
Returns theMimeMessageparsed from the content.- Returns:
- the
MimeMessage.
-
getRawMimeContent
public java.lang.String getRawMimeContent()
Returns the internal raw content received by the SMTP server to parse asMimeMessage.- 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 newSmtpMessagewith the specified parameters.- Parameters:
from- The sourceFromparameter value.recipients- The sourceRcptparameter values.mimeMessageStr- TheMimeMessagecontent.- Returns:
- A new
SmtpMessageinstance.
-
-