Package ch.astorm.smtp4j.util
Class MimeMessageBuilder
java.lang.Object
ch.astorm.smtp4j.util.MimeMessageBuilder
Provides methods to easily create a
MimeMessage that can be sent to an
SMTP server.-
Constructor Summary
ConstructorsConstructorDescriptionMimeMessageBuilder(SmtpServer server) Creates a newMimeMessageBuilderby creating a newSessionfrom the givenserver.MimeMessageBuilder(jakarta.mail.Session session) Creates a newMimeMessageBuilderwith the givensession. -
Method Summary
Modifier and TypeMethodDescriptionDefines the sent date.Defines the sent date.attachment(File file) Adds the specifiedfileas attachment.attachment(String name, File file) Adds the specifiedfileas attachment wit the givenname.attachment(String name, String mimeType, InputStream is) Adds the specifiedfileas attachment wit the givennameandmimeType.bcc(jakarta.mail.Address address) Adds theaddressto theBCCrecipients.Adds theaddressto theBCCrecipients.Defines the message body.Defines the message body.jakarta.mail.internet.MimeMessagebuild()Builds theMimeMessage.cc(jakarta.mail.Address address) Adds theaddressto theCCrecipients.Adds theaddressto theCCrecipients.from(jakarta.mail.Address from) Defines the From address.Defines the From address.jakarta.mail.internet.MimeMessagesend()Builds and send the message.Defines the message subject.Defines the message subject.to(jakarta.mail.Address address) Adds theaddressto theTOrecipients.Adds theaddressto theTOrecipients.toRecipient(jakarta.mail.Message.RecipientType type, jakarta.mail.Address address) Adds theaddressto the specified recipienttype.toRecipient(jakarta.mail.Message.RecipientType type, String... address) Adds theaddressto the specified recipienttype.
-
Constructor Details
-
MimeMessageBuilder
Creates a newMimeMessageBuilderby creating a newSessionfrom the givenserver.- Parameters:
server- The server.- See Also:
-
MimeMessageBuilder
public MimeMessageBuilder(jakarta.mail.Session session) Creates a newMimeMessageBuilderwith the givensession.- Parameters:
session- The session.
-
-
Method Details
-
from
Defines the From address.- Parameters:
from- The from address.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
from
Defines the From address.- Parameters:
from- The from address.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
at
public MimeMessageBuilder at(String sentDate) throws ParseException, jakarta.mail.MessagingException Defines the sent date.- Parameters:
sentDate- The sent date in format 'dd.MM.yyyy HH:mm:ss' (31.12.2020 23:59:59).- Returns:
- This builder.
- Throws:
ParseExceptionjakarta.mail.MessagingException
-
at
Defines the sent date.- Parameters:
sentDate- The sent date.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
to
Adds theaddressto theTOrecipients.- Parameters:
address- The address or a comma-separated list of addresses.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
to
Adds theaddressto theTOrecipients.- Parameters:
address- The address.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
cc
Adds theaddressto theCCrecipients.- Parameters:
address- The address or a comma-separated list of addresses.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
cc
Adds theaddressto theCCrecipients.- Parameters:
address- The address.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
bcc
Adds theaddressto theBCCrecipients.- Parameters:
address- The address or a comma-separated list of addresses.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
bcc
Adds theaddressto theBCCrecipients.- Parameters:
address- The address.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
toRecipient
public MimeMessageBuilder toRecipient(jakarta.mail.Message.RecipientType type, String... address) throws jakarta.mail.MessagingException Adds theaddressto the specified recipienttype.- Parameters:
type- The recipient type.address- The address or a comma-separated list of addresses.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
toRecipient
public MimeMessageBuilder toRecipient(jakarta.mail.Message.RecipientType type, jakarta.mail.Address address) throws jakarta.mail.MessagingException Adds theaddressto the specified recipienttype.- Parameters:
type- The recipient type.address- The address.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
subject
Defines the message subject.- Parameters:
subject- The subject.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
subject
public MimeMessageBuilder subject(String subject, Charset charset) throws jakarta.mail.MessagingException Defines the message subject.- Parameters:
subject- The subject.charset- The character set.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
body
Defines the message body.- Parameters:
body- The body.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
body
Defines the message body.- Parameters:
body- The body.charset- The character set.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
attachment
Adds the specifiedfileas attachment.- Parameters:
file- The file.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
attachment
Adds the specifiedfileas attachment wit the givenname.- Parameters:
name- The name.file- The file.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
attachment
public MimeMessageBuilder attachment(String name, String mimeType, InputStream is) throws IOException, jakarta.mail.MessagingException Adds the specifiedfileas attachment wit the givennameandmimeType.- Parameters:
name- The name.mimeType- The MIME type.is- The input stream.- Returns:
- This builder.
- Throws:
IOExceptionjakarta.mail.MessagingException
-
build
public jakarta.mail.internet.MimeMessage build() throws jakarta.mail.MessagingExceptionBuilds theMimeMessage. This method can be called only once.- Returns:
- The create
MimeMessage. - Throws:
jakarta.mail.MessagingException
-
send
public jakarta.mail.internet.MimeMessage send() throws jakarta.mail.MessagingExceptionBuilds and send the message. This method can be called only once.- Returns:
- The sent message.
- Throws:
jakarta.mail.MessagingException
-