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(javax.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(java.lang.String... address)Adds theaddressto theBCCrecipients.MimeMessageBuilderbcc(javax.mail.Address 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.javax.mail.internet.MimeMessagebuild()Builds theMimeMessage.MimeMessageBuildercc(java.lang.String... address)Adds theaddressto theCCrecipients.MimeMessageBuildercc(javax.mail.Address address)Adds theaddressto theCCrecipients.MimeMessageBuilderfrom(java.lang.String from)Defines the From address.MimeMessageBuilderfrom(javax.mail.Address from)Defines the From address.javax.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(java.lang.String... address)Adds theaddressto theTOrecipients.MimeMessageBuilderto(javax.mail.Address address)Adds theaddressto theTOrecipients.MimeMessageBuildertoRecipient(javax.mail.Message.RecipientType type, java.lang.String... address)Adds theaddressto the specified recipienttype.MimeMessageBuildertoRecipient(javax.mail.Message.RecipientType type, javax.mail.Address 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(javax.mail.Session session)
Creates a newMimeMessageBuilderwith the givensession.- Parameters:
session- The session.
-
-
Method Detail
-
from
public MimeMessageBuilder from(java.lang.String from) throws javax.mail.MessagingException
Defines the From address.- Parameters:
from- The from address.- Returns:
- This builder.
- Throws:
javax.mail.MessagingException
-
from
public MimeMessageBuilder from(javax.mail.Address from) throws javax.mail.MessagingException
Defines the From address.- Parameters:
from- The from address.- Returns:
- This builder.
- Throws:
javax.mail.MessagingException
-
at
public MimeMessageBuilder at(java.lang.String sentDate) throws java.text.ParseException, javax.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.ParseExceptionjavax.mail.MessagingException
-
at
public MimeMessageBuilder at(java.util.Date sentDate) throws javax.mail.MessagingException
Defines the sent date.- Parameters:
sentDate- The sent date.- Returns:
- This builder.
- Throws:
javax.mail.MessagingException
-
to
public MimeMessageBuilder to(java.lang.String... address) throws javax.mail.MessagingException
Adds theaddressto theTOrecipients.- Parameters:
address- The address or a comma-separated list of addresses.- Returns:
- This builder.
- Throws:
javax.mail.MessagingException
-
to
public MimeMessageBuilder to(javax.mail.Address address) throws javax.mail.MessagingException
Adds theaddressto theTOrecipients.- Parameters:
address- The address.- Returns:
- This builder.
- Throws:
javax.mail.MessagingException
-
cc
public MimeMessageBuilder cc(java.lang.String... address) throws javax.mail.MessagingException
Adds theaddressto theCCrecipients.- Parameters:
address- The address or a comma-separated list of addresses.- Returns:
- This builder.
- Throws:
javax.mail.MessagingException
-
cc
public MimeMessageBuilder cc(javax.mail.Address address) throws javax.mail.MessagingException
Adds theaddressto theCCrecipients.- Parameters:
address- The address.- Returns:
- This builder.
- Throws:
javax.mail.MessagingException
-
bcc
public MimeMessageBuilder bcc(java.lang.String... address) throws javax.mail.MessagingException
Adds theaddressto theBCCrecipients.- Parameters:
address- The address or a comma-separated list of addresses.- Returns:
- This builder.
- Throws:
javax.mail.MessagingException
-
bcc
public MimeMessageBuilder bcc(javax.mail.Address address) throws javax.mail.MessagingException
Adds theaddressto theBCCrecipients.- Parameters:
address- The address.- Returns:
- This builder.
- Throws:
javax.mail.MessagingException
-
toRecipient
public MimeMessageBuilder toRecipient(javax.mail.Message.RecipientType type, java.lang.String... address) throws javax.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:
javax.mail.MessagingException
-
toRecipient
public MimeMessageBuilder toRecipient(javax.mail.Message.RecipientType type, javax.mail.Address address) throws javax.mail.MessagingException
Adds theaddressto the specified recipienttype.- Parameters:
type- The recipient type.address- The address.- Returns:
- This builder.
- Throws:
javax.mail.MessagingException
-
subject
public MimeMessageBuilder subject(java.lang.String subject) throws javax.mail.MessagingException
Defines the message subject.- Parameters:
subject- The subject.- Returns:
- This builder.
- Throws:
javax.mail.MessagingException
-
subject
public MimeMessageBuilder subject(java.lang.String subject, java.nio.charset.Charset charset) throws javax.mail.MessagingException
Defines the message subject.- Parameters:
subject- The subject.charset- The character set.- Returns:
- This builder.
- Throws:
javax.mail.MessagingException
-
body
public MimeMessageBuilder body(java.lang.String body) throws javax.mail.MessagingException
Defines the message body.- Parameters:
body- The body.- Returns:
- This builder.
- Throws:
javax.mail.MessagingException
-
body
public MimeMessageBuilder body(java.lang.String body, java.nio.charset.Charset charset) throws javax.mail.MessagingException
Defines the message body.- Parameters:
body- The body.charset- The character set.- Returns:
- This builder.
- Throws:
javax.mail.MessagingException
-
attachment
public MimeMessageBuilder attachment(java.io.File file) throws javax.mail.MessagingException
Adds the specifiedfileas attachment.- Parameters:
file- The file.- Returns:
- This builder.
- Throws:
javax.mail.MessagingException
-
attachment
public MimeMessageBuilder attachment(java.lang.String name, java.io.File file) throws javax.mail.MessagingException
Adds the specifiedfileas attachment wit the givenname.- Parameters:
name- The name.file- The file.- Returns:
- This builder.
- Throws:
javax.mail.MessagingException
-
attachment
public MimeMessageBuilder attachment(java.lang.String name, java.lang.String mimeType, java.io.InputStream is) throws java.io.IOException, javax.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.IOExceptionjavax.mail.MessagingException
-
build
public javax.mail.internet.MimeMessage build() throws javax.mail.MessagingExceptionBuilds theMimeMessage. This method can be called only once.- Returns:
- The create
MimeMessage. - Throws:
javax.mail.MessagingException
-
send
public javax.mail.internet.MimeMessage send() throws javax.mail.MessagingExceptionBuilds and send the message. This method can be called only once.- Returns:
- The sent message.
- Throws:
javax.mail.MessagingException
-
-