I\'m starting with the amazon servers and started studying about SES. I am using asp.net C # and made my code based tutorials. I already checked the domain and also chec
Your code indicates that you are trying to send via us-west-2
. Have you requested production access in that region, and is your From
address verified? Production access for Amazon SES is region-independent and you need to request it separately for each region.
If you do not have production access, you should make sure that both From
and To
addresses are verified. The Amazon SES console will list your verified email addresses and verified domains for us-west-2
. The Amazon SES blog has additional guidance on how you can get set up in us-west-2
.
A quick way to tell if you do not have production access: log in to the Amazon SES console dashboard and it will display a blue banner with the following text at the top of the page with a button to request production access:
Your Amazon SES account has "sandbox" access in region US West (Oregon). With sandbox access you can only send email to the Amazon SES mailbox simulator and to email addresses or domains that you have verified. Learn more.
Can't find your existing account settings? Your account may be set up in a different AWS region. Try switching regions in the upper right corner of the console.
After weeks of messing around, I finally sorted this out. So if you are out of the sandbox, have verified your domain and your FROM email address, beware of the default Region. As you already know (just a guess), being out of the sandbox is region-specific (as well as the verified email and domain).
My problem was that I was that in all of the permutations of how to send an email with AWS SDK Java, I was not able to specify an explicit region and my USA account was defaulting the region to USA West. My Region where I did all of the verification (and was out of the Sandbox) was Europe West (email-smtp.eu-west-1.amazonaws.com). Also don't forget to use the proper credentials for Amazon SES API which are the AWS access keys. In my case (below) those keys are in a file, in the classpath with two key-value pairs:
accessKey = AKI...
secretKey = AsVyp...
And here is the code:
import java.io.IOException;
import java.util.ArrayList;
import java.util.Properties;
import java.util.Arrays;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import com.amazonaws.auth.PropertiesCredentials;
import com.amazonaws.services.simpleemail.AWSJavaMailTransport;
import com.amazonaws.services.simpleemail.AmazonSimpleEmailService;
import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClient;
import com.amazonaws.services.simpleemail.model.ListVerifiedEmailAddressesResult;
import com.amazonaws.services.simpleemail.model.VerifyEmailAddressRequest;
//import com.amazonaws.services.ec2.model.Region;
import com.amazonaws.services.simpleemail.*;
import com.amazonaws.services.simpleemail.model.*;
import com.amazonaws.regions.*;
public class AmazonSESSample {
static final String FROM = "john@myappsdomain.com";
static final String TO = "me@mypersonalaccount.com"; //
static final String BODY = "This email was sent through Amazon SES by using the AWS SDK for Java.";
static final String SUBJECT = "Amazon SES test (AWS SDK for Java)";
public static void main(String[] args) throws IOException {
// Construct an object to contain the recipient address.
Destination destination = new Destination().withToAddresses(new String[]{TO});
// Create the subject and body of the message.
Content subject = new Content().withData(SUBJECT);
Content textBody = new Content().withData(BODY);
Body body = new Body().withText(textBody);
PropertiesCredentials credentials = new PropertiesCredentials(
AmazonSESSample.class
.getResourceAsStream("AwsCredentials.properties"));
Message message = new Message().withSubject(subject).withBody(body);
SendEmailRequest request = new SendEmailRequest().withSource(FROM).withDestination(destination).withMessage(message);
try
{
AmazonSimpleEmailServiceClient client = new AmazonSimpleEmailServiceClient(credentials);
Region REGION = Region.getRegion(Regions.EU_WEST_1);
client.setRegion(REGION);
client.sendEmail(request);
System.out.println("Email sent!");
}
catch (Exception ex)
{
System.out.println("The email was not sent.");
System.out.println("Error message: " + ex.getMessage());
}
}
}
Also double check to make sure your not running in production mode and/or make sure your sending TO address is verified in Sandbox Mode.
Limitations of AWS SES Sandbox Mode:
http://docs.aws.amazon.com/ses/latest/DeveloperGuide/request-production-access.html
Are you by chance still running in 'sandbox' mode? If you are, you can only send emails to addresses that have been pre-verified.
From Amazon:
Email address is not verified—Your account is in the sandbox and one of the recipient email addresses has not been verified. This might apply to "Sender", "Return-Path", or "From" addresses.
If you have not requested production access to Amazon SES, you must verify every recipient email address except for the recipients provided by the Amazon SES mailbox simulator. You must also verify your own "From" address. For more information, see Verifying Email Addresses and Domains in Amazon SES and Testing Amazon SES Email Sending.
More information here: http://docs.aws.amazon.com/ses/latest/DeveloperGuide/ses-errors.html