Package ch.astorm.smtp4j.util
Class MimeMessageBuilder
- java.lang.Object
-
- ch.astorm.smtp4j.util.MimeMessageBuilder
-
public class MimeMessageBuilder extends java.lang.ObjectProvides methods to easily create aMimeMessagethat can be sent to an SMTP server.
-
-
Constructor Summary
Constructors Constructor Description MimeMessageBuilder(SmtpServer server)Creates a newMimeMessageBuilderby creating a newSessionfrom the givenserver.MimeMessageBuilder(jakarta.mail.Session session)Creates a newMimeMessageBuilderwith the givensession.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MimeMessageBuilderat(java.lang.String sentDate)Defines the sent date.MimeMessageBuilderat(java.util.Date sentDate)Defines the sent date.MimeMessageBuilderattachment(java.io.File file)Adds the specifiedfileas attachment.MimeMessageBuilderattachment(java.lang.String name, java.io.File file)Adds the specifiedfileas attachment wit the givenname.MimeMessageBuilderattachment(java.lang.String name, java.lang.String mimeType, java.io.InputStream is)Adds the specifiedfileas attachment wit the givennameandmimeType.MimeMessageBuilderbcc(jakarta.mail.Address address)Adds theaddressto theBCCrecipients.MimeMessageBuilderbcc(java.lang.String... address)Adds theaddressto theBCCrecipients.MimeMessageBuilderbody(java.lang.String body)Defines the message body.MimeMessageBuilderbody(java.lang.String body, java.nio.charset.Charset charset)Defines the message body.jakarta.mail.internet.MimeMessagebuild()Builds theMimeMessage.MimeMessageBuildercc(jakarta.mail.Address address)Adds theaddressto theCCrecipients.MimeMessageBuildercc(java.lang.String... address)Adds theaddressto theCCrecipients.MimeMessageBuilderfrom(jakarta.mail.Address from)Defines the From address.MimeMessageBuilderfrom(java.lang.String from)Defines the From address.jakarta.mail.internet.MimeMessagesend()Builds and send the message.MimeMessageBuildersubject(java.lang.String subject)Defines the message subject.MimeMessageBuildersubject(java.lang.String subject, java.nio.charset.Charset charset)Defines the message subject.MimeMessageBuilderto(jakarta.mail.Address address)Adds theaddressto theTOrecipients.MimeMessageBuilderto(java.lang.String... address)Adds theaddressto theTOrecipients.MimeMessageBuildertoRecipient(jakarta.mail.Message.RecipientType type, jakarta.mail.Address address)Adds theaddressto the specified recipienttype.MimeMessageBuildertoRecipient(jakarta.mail.Message.RecipientType type, java.lang.String... address)Adds theaddressto the specified recipienttype.
-
-
-
Constructor Detail
-
MimeMessageBuilder
public MimeMessageBuilder(SmtpServer server)
Creates a newMimeMessageBuilderby creating a newSessionfrom the givenserver.- Parameters:
server- The server.- See Also:
SmtpServer.createSession()
-
MimeMessageBuilder
public MimeMessageBuilder(jakarta.mail.Session session)
Creates a newMimeMessageBuilderwith the givensession.- Parameters:
session- The session.
-
-
Method Detail
-
from
public MimeMessageBuilder from(java.lang.String from) throws jakarta.mail.MessagingException
Defines the From address.- Parameters:
from- The from address.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
from
public MimeMessageBuilder from(jakarta.mail.Address from) throws jakarta.mail.MessagingException
Defines the From address.- Parameters:
from- The from address.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
at
public MimeMessageBuilder at(java.lang.String sentDate) throws java.text.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:
java.text.ParseExceptionjakarta.mail.MessagingException
-
at
public MimeMessageBuilder at(java.util.Date sentDate) throws jakarta.mail.MessagingException
Defines the sent date.- Parameters:
sentDate- The sent date.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
to
public MimeMessageBuilder to(java.lang.String... address) throws jakarta.mail.MessagingException
Adds theaddressto theTOrecipients.- Parameters:
address- The address or a comma-separated list of addresses.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
to
public MimeMessageBuilder to(jakarta.mail.Address address) throws jakarta.mail.MessagingException
Adds theaddressto theTOrecipients.- Parameters:
address- The address.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
cc
public MimeMessageBuilder cc(java.lang.String... address) throws jakarta.mail.MessagingException
Adds theaddressto theCCrecipients.- Parameters:
address- The address or a comma-separated list of addresses.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
cc
public MimeMessageBuilder cc(jakarta.mail.Address address) throws jakarta.mail.MessagingException
Adds theaddressto theCCrecipients.- Parameters:
address- The address.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
bcc
public MimeMessageBuilder bcc(java.lang.String... address) throws jakarta.mail.MessagingException
Adds theaddressto theBCCrecipients.- Parameters:
address- The address or a comma-separated list of addresses.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
bcc
public MimeMessageBuilder bcc(jakarta.mail.Address address) throws jakarta.mail.MessagingException
Adds theaddressto theBCCrecipients.- Parameters:
address- The address.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
toRecipient
public MimeMessageBuilder toRecipient(jakarta.mail.Message.RecipientType type, java.lang.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
public MimeMessageBuilder subject(java.lang.String subject) throws jakarta.mail.MessagingException
Defines the message subject.- Parameters:
subject- The subject.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
subject
public MimeMessageBuilder subject(java.lang.String subject, java.nio.charset.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
public MimeMessageBuilder body(java.lang.String body) throws jakarta.mail.MessagingException
Defines the message body.- Parameters:
body- The body.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
body
public MimeMessageBuilder body(java.lang.String body, java.nio.charset.Charset charset) throws jakarta.mail.MessagingException
Defines the message body.- Parameters:
body- The body.charset- The character set.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
attachment
public MimeMessageBuilder attachment(java.io.File file) throws jakarta.mail.MessagingException
Adds the specifiedfileas attachment.- Parameters:
file- The file.- Returns:
- This builder.
- Throws:
jakarta.mail.MessagingException
-
attachment
public MimeMessageBuilder attachment(java.lang.String name, java.io.File file) throws jakarta.mail.MessagingException
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(java.lang.String name, java.lang.String mimeType, java.io.InputStream is) throws java.io.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:
java.io.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
-
-