public class EmailTransaction extends Object
This object allows emails to take part in transactional operations.
Any part of the code may send(Message) emails using this transaction.
They get stored in memory, and only really get sent when commit() is called.
This way, if an exception occurs after the email gets sent, and the operation is successfully
retried, the recipient only gets one email based on the successful operation and no emails
based on the unsuccessful operation.
There is no need to rollback this object if an operation has been not successful. Simply throw the object away.
| Modifier and Type | Class and Description |
|---|---|
static class |
EmailTransaction.EmailSendingConfiguration |
static class |
EmailTransaction.MxSmtpConfiguration |
static class |
EmailTransaction.SmtpServerAddress |
static class |
EmailTransaction.SmtpServerConfiguration |
static class |
EmailTransaction.TlsSmtpServerAddress |
| Modifier and Type | Field and Description |
|---|---|
protected EmailTransaction.EmailSendingConfiguration |
config |
protected List<javax.mail.Message> |
messages |
| Constructor and Description |
|---|
EmailTransaction(EmailTransaction.EmailSendingConfiguration config) |
| Modifier and Type | Method and Description |
|---|---|
void |
commit() |
String |
getEmailBodyForTesting(int idx) |
int |
getEmailCountForTesting() |
protected static String |
getHostForMxRecord(String mxAddress) |
javax.mail.internet.MimeMessage |
newMimeMessage() |
protected javax.mail.Session |
newSession() |
protected Properties |
newSessionProperties() |
static EmailTransaction.SmtpServerConfiguration |
parseAddress(String str)
Can be "foo" or "foo:123" or "foo:123|adrian|password" or "MX:foo.com"
|
void |
send(javax.mail.Message msg) |
@Nonnull protected final EmailTransaction.EmailSendingConfiguration config
protected final List<javax.mail.Message> messages
public EmailTransaction(@Nonnull EmailTransaction.EmailSendingConfiguration config) throws ConfigurationException
ConfigurationExceptionprotected static String getHostForMxRecord(String mxAddress) throws ConfigurationException
ConfigurationExceptionprotected Properties newSessionProperties() throws ConfigurationException
ConfigurationExceptionprotected javax.mail.Session newSession()
throws ConfigurationException
ConfigurationException@Nonnull public static EmailTransaction.SmtpServerConfiguration parseAddress(@Nonnull String str) throws ConfigurationException
ConfigurationException@Nonnull public javax.mail.internet.MimeMessage newMimeMessage()
public void send(javax.mail.Message msg)
public void commit()
public int getEmailCountForTesting()
public String getEmailBodyForTesting(int idx)
Copyright © 2003–2018. All rights reserved.