Package com.adaptris.mail
Interface MailSender
- All Known Implementing Classes:
MailSenderImp,SmtpClient
public interface MailSender
An interface for an email sender client.
The javax.mail MimeMessage and Session objects are used at least to hold message data although the client implementation may not necessarily use javax.mail system, in which case a conversion will be required to store data in the MimeMessage object.
Expected usage:- construct client sender object add/remove session properties start session call newMessage method call setFrom, addTo/cc/Bcc, setSubject, setMessage, addAttachments as required call send
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddAttachment(byte[] bytes, String filename, String type) Add an attachment to the email.voidaddAttachment(byte[] bytes, String filename, String type, String encoding) Add an attachment to the email.voidaddAttachment(Attachment attachment) Add an attachment to the email.voidaddBlindCarbonCopy(String bcc) Add a name to the BCC list.voidaddBlindCarbonCopy(javax.mail.internet.InternetAddress[] bcc) Add some names to the BCC list.voidaddCarbonCopy(String cc) Add some names to the CC list.voidaddCarbonCopy(javax.mail.internet.InternetAddress[] cc) Add some names to the CC list.voidaddMailHeader(String key, String value) Add a header to the mail header.voidaddSessionProperty(String key, String value) Add a property to the set of properties used by the SMTP Session.voidAdd some names to the TO list.voidaddTo(javax.mail.internet.InternetAddress[] address) Add some names to the TO list.voidCreate a new message Must be called prior to setting recipient list, mail body etc.voidremoveMailHeader(String key) Remove a mail header.voidRemove a property from the set of properties used by the SMTP Session.voidsend()Send the email.voidsetEncoding(String enc) Set the encoding type to use for the message type.voidSet the sender.voidsetFrom(javax.mail.internet.InternetAddress from) Set the sender.voidsetMessage(byte[] bytes) Set the messagevoidsetMessage(byte[] bytes, String contentType) Set the message and content type Content type maybe an arbitary string such as application/edi-x12, although if an appropriateDataContentHandleris not installed, then the results can be undefined.voidsetSubject(String s) Set the subject of the email.voidStart session based on session properties This may be used to initialise the client prior to sending any mail
-
Method Details
-
addSessionProperty
Add a property to the set of properties used by the SMTP Session.- Parameters:
key- the keyvalue- the value.
-
removeSessionProperty
Remove a property from the set of properties used by the SMTP Session.- Parameters:
key- the key
-
startSession
Start session based on session properties This may be used to initialise the client prior to sending any mail- Throws:
MailException
-
newMessage
Create a new message Must be called prior to setting recipient list, mail body etc.- Throws:
MailException
-
addMailHeader
Add a header to the mail header.- Parameters:
key- the keyvalue- the value.- Throws:
MailException
-
removeMailHeader
Remove a mail header.- Parameters:
key- the key- Throws:
MailException
-
addTo
Add some names to the TO list.- Parameters:
address- an array of InternetAddress[] representing email addresses- Throws:
MailException- if the addresses could not be parsed.
-
addTo
Add some names to the TO list.- Parameters:
address- the email address name@company.com- Throws:
MailException- if the addresses could not be parsed.
-
addCarbonCopy
Add some names to the CC list.- Parameters:
cc- an array of InternetAddress[] representing email addresses- Throws:
MailException- if the addresses could not be parsed.
-
addCarbonCopy
Add some names to the CC list.- Parameters:
cc- the email address name@company.com- Throws:
MailException- if the addresses could not be parsed.
-
addBlindCarbonCopy
Add some names to the BCC list.- Parameters:
bcc- an array of InternetAddress[] representing email addresses- Throws:
MailException- if the addresses could not be parsed.
-
addBlindCarbonCopy
Add a name to the BCC list.- Parameters:
bcc- email address name@company.com- Throws:
MailException- if the addresses could not be parsed.
-
setFrom
Set the sender.- Parameters:
from- email address name@company.com- Throws:
MailException- if the addresses could not be parsed.
-
setFrom
Set the sender.- Parameters:
from- InternetAddress container for name@company.com- Throws:
MailException- if the addresses could not be parsed.
-
setSubject
Set the subject of the email.- Parameters:
s- the subject.- Throws:
MailException
-
addAttachment
void addAttachment(byte[] bytes, String filename, String type, String encoding) throws MailException Add an attachment to the email.- Parameters:
bytes- the attachment;filename- the filename to use for the attachment.type- the content type to associate with this attachmentencoding- of the mime body part for this attachment- Throws:
MailException
-
addAttachment
Add an attachment to the email.- Parameters:
bytes- the attachment;filename- the filename to use for the attachment.type- the content type to associate with this attachment- Throws:
MailException
-
addAttachment
Add an attachment to the email.- Parameters:
attachment- object;- Throws:
MailException
-
setMessage
Set the message and content type Content type maybe an arbitary string such as application/edi-x12, although if an appropriateDataContentHandleris not installed, then the results can be undefined.- Parameters:
bytes- the messagecontentType- the content type.- Throws:
MailException- See Also:
-
DataContentHandler
-
setMessage
Set the message- Parameters:
bytes- the message;- Throws:
MailException
-
setEncoding
Set the encoding type to use for the message type.Valid types of encoding are those defined in RFC2045. They include "base64", "quoted-printable", "7bit", "8bit" and "binary". In addition, "uuencode" is also supported.
- Parameters:
enc- the encoding type to use.
-
send
Send the email.- Throws:
MailException- wrapping any underlying exception
-