Class AWSJavaMailTransport
- java.lang.Object
-
- javax.mail.Service
-
- javax.mail.Transport
-
- com.amazonaws.services.simpleemail.AWSJavaMailTransport
-
- All Implemented Interfaces:
AutoCloseable
public class AWSJavaMailTransport extends javax.mail.TransportA transport implementation using Amazon Web Service's E-mail Service. For JavaMail purposes this transport implementation uses the "aws" protocol. In order to send messages through the E-mail Service your AWS Credentials (http://aws.amazon.com/security-credentials) need to be either in the JavaMail Session's Properties (mail.aws.user and mail.aws.password), passed into the connect() method, or set in the Session's setPasswordAuthentication method. Parameters passed into the connect method as well as PasswordAuthentication information supersedes the properties field for a particular session. When connecting your AWS Access Key is your username and your AWS Secret Key is your password.This transport implementation only accepts MIME encoded messages (see MimeMessage class) and RFC822 E-mail addresses (see InternetAddress class).
-
-
Field Summary
Fields Modifier and Type Field Description static StringAWS_ACCESS_KEY_PROPERTYstatic StringAWS_EMAIL_SERVICE_ENDPOINT_PROPERTYstatic StringAWS_SECRET_KEY_PROPERTY
-
Constructor Summary
Constructors Constructor Description AWSJavaMailTransport(javax.mail.Session session, javax.mail.URLName urlname)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <X extends AmazonWebServiceRequest>
XappendUserAgent(X request, String userAgent)voidclose()StringgetLastMessageId()The unique message identifier ot the last message sent bysendMessageprotected booleanprotocolConnect(String host, int port, String awsAccessKey, String awsSecretKey)Sets up a new AmazonSimpleEmailServiceClient.voidsendMessage(javax.mail.Message msg, javax.mail.Address[] addresses)Sends a MIME message through Amazon's E-mail Service with the specified recipients.-
Methods inherited from class javax.mail.Transport
addTransportListener, notifyTransportListeners, removeTransportListener, send, send, send, send
-
-
-
-
Field Detail
-
AWS_EMAIL_SERVICE_ENDPOINT_PROPERTY
public static final String AWS_EMAIL_SERVICE_ENDPOINT_PROPERTY
- See Also:
- Constant Field Values
-
AWS_SECRET_KEY_PROPERTY
public static final String AWS_SECRET_KEY_PROPERTY
- See Also:
- Constant Field Values
-
AWS_ACCESS_KEY_PROPERTY
public static final String AWS_ACCESS_KEY_PROPERTY
- See Also:
- Constant Field Values
-
-
Method Detail
-
sendMessage
public void sendMessage(javax.mail.Message msg, javax.mail.Address[] addresses) throws javax.mail.MessagingException, javax.mail.SendFailedExceptionSends a MIME message through Amazon's E-mail Service with the specified recipients. Addresses that are passed into this method are merged with the ones already embedded in the message (duplicates are removed).- Specified by:
sendMessagein classjavax.mail.Transport- Parameters:
msg- A Mime type e-mail message to be sentaddresses- Additional e-mail addresses (RFC-822) to be included in the message- Throws:
javax.mail.MessagingExceptionjavax.mail.SendFailedException
-
protocolConnect
protected boolean protocolConnect(String host, int port, String awsAccessKey, String awsSecretKey)
Sets up a new AmazonSimpleEmailServiceClient. This method is typically called indirectly from the connect() method and should only be called on instantiation or to reopen after a close(). If a non-null or empty User and Password passed in session properties are overridden while user remains connected (mail.aws.user and mail.aws.password). The default https endpoint is specified by the mail client; however, it can be overridden by either passing in a value or setting mail.aws.host. Like the user and password, the variable that is passed in takes preference over the properties file.- Overrides:
protocolConnectin classjavax.mail.Service- Parameters:
host- Optional - host specifies the AWS E-mail endpointawsAccessKey- Optional - AWS Access Key (otherwise must specify through properties file)awsSecretKey- Optional - AWS Secret key (otherwise must specify through properties file)- Returns:
- Returns true if non-empty credentials are given
-
close
public void close() throws javax.mail.MessagingException- Specified by:
closein interfaceAutoCloseable- Overrides:
closein classjavax.mail.Service- Throws:
javax.mail.MessagingException
-
getLastMessageId
public String getLastMessageId()
The unique message identifier ot the last message sent by
sendMessage- Returns:
- The unique message identifier sent by the last
sendMessageaction.
-
appendUserAgent
public <X extends AmazonWebServiceRequest> X appendUserAgent(X request, String userAgent)
-
-