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());
}
}
}