List of usage examples for com.amazonaws.auth PropertiesCredentials getAWSSecretKey
public String getAWSSecretKey()
From source file:AWSJavaMailSample.java
License:Open Source License
public static void main(String[] args) throws IOException { /*/*from www. j av a 2s.c om*/ * Important: Be sure to fill in your AWS access credentials in the * AwsCredentials.properties file before you try to run this sample. * http://aws.amazon.com/security-credentials */ PropertiesCredentials credentials = new PropertiesCredentials( AWSJavaMailSample.class.getResourceAsStream("AwsCredentials.properties")); AmazonSimpleEmailService ses = new AmazonSimpleEmailServiceClient(credentials); /* * Before you can send email via Amazon SES, you need to verify that you * own the email address from which youll be sending email. This will * trigger a verification email, which will contain a link that you can * click on to complete the verification process. */ verifyEmailAddress(ses, FROM); /* * If you've just signed up for SES, then you'll be placed in the Amazon * SES sandbox, where you must also verify the email addresses you want * to send mail to. * * You can uncomment the line below to verify the TO address in this * sample. * * Once you have full access to Amazon SES, you will *not* be required * to verify each email address you want to send mail to. * * You can request full access to Amazon SES here: * http://aws.amazon.com/ses/fullaccessrequest */ //verifyEmailAddress(ses, TO); /* * Setup JavaMail to use the Amazon Simple Email Service by specifying * the "aws" protocol. */ Properties props = new Properties(); 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(); } catch (AddressException e) { e.printStackTrace(); System.out.println("Caught an AddressException, which means one or more of your " + "addresses are improperly formatted."); } catch (MessagingException e) { e.printStackTrace(); System.out.println("Caught a MessagingException, which means that there was a " + "problem sending your message to Amazon's E-mail Service check the " + "stack trace for more information."); } }
From source file:aws.sample.AWSJavaMailSample.java
License:Open Source License
public static void main(String[] args) throws IOException { /*/* w w w . j a va 2 s.co m*/ * Important: Be sure to fill in your AWS access credentials in the AwsCredentials.properties file before you try to run this sample. http://aws.amazon.com/security-credentials */ PropertiesCredentials credentials = new PropertiesCredentials( AWSJavaMailSample.class.getResourceAsStream("/AwsCredentials.properties")); AmazonSimpleEmailService ses = new AmazonSimpleEmailServiceClient(credentials); /* * Before you can send email via Amazon SES, you need to verify that you own the email address from which you?l be sending email. This will trigger a verification email, which will contain a link that you can click on to complete the verification process. */ verifyEmailAddress(ses, FROM); /* * If you've just signed up for SES, then you'll be placed in the Amazon SES sandbox, where you must also verify the email addresses you want to send mail to. * * You can uncomment the line below to verify the TO address in this sample. * * Once you have full access to Amazon SES, you will *not* be required to verify each email address you want to send mail to. * * You can request full access to Amazon SES here: http://aws.amazon.com/ses/fullaccessrequest */ // verifyEmailAddress(ses, TO); /* * Setup JavaMail to use the Amazon Simple Email Service by specifying the "aws" protocol. */ Properties props = new Properties(); 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(); } catch (AddressException e) { e.printStackTrace(); System.out.println("Caught an AddressException, which means one or more of your " + "addresses are improperly formatted."); } catch (MessagingException e) { e.printStackTrace(); System.out.println("Caught a MessagingException, which means that there was a " + "problem sending your message to Amazon's E-mail Service check the " + "stack trace for more information."); } }