commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Nathan Maves <nathan.ma...@gmail.com>
Subject [Email] Using Amazon Simple Email Service SES
Date Wed, 16 Feb 2011 04:47:22 GMT
Has anyone been able to use this service with commons email?  I can't seem
to wrap my head around how to do it.

Here here is bit of their sample code....

              PropertiesCredentials credentials = new PropertiesCredentials(
 AWSJavaMailSample.class
.getResourceAsStream("AwsCredentials.properties"));

Properties props = new Properties();

       /*
         * Setup JavaMail to use the Amazon Simple Email Service by
        * specifying the "aws" protocol.
 */
props.setProperty("mail.transport.protocol", "aws");

/*
 * Setting mail.aws.user and mail.aws.password are optional. Setting
 * these will allow you to send mail using the static transport send()
 * convince method.  It will also allow you to call connect() with no
 * parameters. Otherwise, a user name and password must be specified
 * in connect.
 */
props.setProperty("mail.aws.user", credentials.getAWSAccessKeyId());
 props.setProperty("mail.aws.password", credentials.getAWSSecretKey());

Session session = Session.getInstance(props);

try {
// Create a new Message
Message msg = new MimeMessage(session);
 msg.setFrom(new InternetAddress(FROM));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(TO));
 msg.setSubject(SUBJECT);
msg.setText(BODY);
msg.saveChanges();

// Reuse one Transport object for sending all your messages
// for better performance
 Transport t = new AWSJavaMailTransport(session, null);
t.connect();
t.sendMessage(msg, null);

// Close your transport when you're completely done sending
// all your messages
 t.close();

}

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message