If you have been approved for production request, make sure the sender email address is approved.
Showing posts with label ses. Show all posts
Showing posts with label ses. Show all posts
Saturday, February 2, 2013
Amazon SES om.sun.mail.smtp.SMTPSendFailedException: 554 Message rejected: Email address is not verified.
If you are in the sandbox, make sure you verified both the receiver and sender email addresses.
Thursday, January 24, 2013
Setting up a Java Tomcat7 Production Server on Amazon EC2
This tutorial will demonstrate how to build a Tomcat7 server running a Java application on Amazon EC2.
Here are the tools we will set up:
- Apache Tomcat7
- Open JDK7
- GitHub
- Maven 3.0.4
- MySQL
Creating a EC2 Instance
In the AWS Management Console, begin by creating a t1.micro Ubuntu Server 12.04.1 LTS 64-bit machine. (If you don't know how to create an instance, read Amazon EC2 - Launching Ubuntu SErver 12.04.1 LTS step by step guide.)
Here are some guidelines:
- Uncheck Delete on Termination for the root volume
- Add port 22, 80, 443 to the Security Group.
Create a EBS volume
We will create a 20GB volume to store our Java code. The EBS will be formated with XFS.
If the volume kept on getting stuck, keep restarting the EC2 instance until it's attached.
Configure the EC2 instance
ssh into the instance (ssh -i {key} ubuntu@{your_ec2_public_address})
sudo apt-get update -y
My mounting point for /dev/xvdf is called /vol.
cd /vol
mkdir src
mkdir webapps
mkdir war_backups
/vol/src is where we will place the application code. /vol/webapps is where we will deploy the WAR file. /vol/war_backups is for making war backups, as the name implies.
Deploying code from GitHub
Skip this if you are using other source control. The idea is that we will put the Java application code in the /vol/src folder.
sudo apt-get install git -y
mkdir /vol/src
cd /vol/src
git config --global user.name "your_name"
git config --global user.email "your_email"
git config --global github.user "your_github_login"
git clone ssh://git@github.com/username/repo.git
You will want to establish a connection with Github using ssh rather than https because if you are building an image that can be used for auto-scaling you don't want to input the username and password every time. See Generating SSH Keys for more details.
Your project should be located in /vol/src/{your_project}
Set up the Tomcat7 server
Begin by reading Install OpenJDK 7. Read Install Java OpenJDK 7 on Amazon EC2 Ubuntu.
echo $JAVA_HOME to check if it's set.
Install Tomcat 7. Read Install Tomcat 7 on Amazon EC2 Ubuntu.
Remember to change to ports 80, 443, and the root web directory as the Tomcat war root path.
Check http://{your_ec2_public_address} in your browser to make sure Tomcat7 is running.
Make sure Tomcat7 is still up after you reboot the machine.
Generating the war file
We will be using Maven to compile our Spring Java project. If you are using other build frameworks, skip this.
Read Install Maven 3 on Amazon EC2 Ubuntu.
mkdir /vol/src
cd /vol/src
git config --global user.name "your_name"
git config --global user.email "your_email"
git config --global github.user "your_github_login"
git clone ssh://git@github.com/username/repo.git
You will want to establish a connection with Github using ssh rather than https because if you are building an image that can be used for auto-scaling you don't want to input the username and password every time. See Generating SSH Keys for more details.
Your project should be located in /vol/src/{your_project}
Set up the Tomcat7 server
Begin by reading Install OpenJDK 7. Read Install Java OpenJDK 7 on Amazon EC2 Ubuntu.
echo $JAVA_HOME to check if it's set.
Install Tomcat 7. Read Install Tomcat 7 on Amazon EC2 Ubuntu.
Remember to change to ports 80, 443, and the root web directory as the Tomcat war root path.
Check http://{your_ec2_public_address} in your browser to make sure Tomcat7 is running.
Make sure Tomcat7 is still up after you reboot the machine.
Generating the war file
We will be using Maven to compile our Spring Java project. If you are using other build frameworks, skip this.
Read Install Maven 3 on Amazon EC2 Ubuntu.
Run "mvn --version" to make sure it's using OpenJDK 7 and running the latest version of Maven.
cd /vol/src/{your_project}
mvn clean install
A WAR file should be built.
Move this WAR file into the Tomcat webapps directory. If you are following this tutorial, it should be at /vol/webapps.
Remember to label this WAR file as ROOT.war
It's easier to do load balancing mapping later.
Remember to label this WAR file as ROOT.war
It's easier to do load balancing mapping later.
Browse to check you can access the site.
Using Amazon SES as the SMTP email service
Using SES will increase the likelihood of email delivery. Read Using Amazon SES to send emails.
Recompile your project and test it.
Moving MySQL to Amazon RDS
If you are using MySQL, you should move to Amazon RDS as it simplifies a lot of management, backup operations for you.
Read Using MySQL on Amazon RDS.
To interact with RDS through your EC2 instance, install MySQL Server or just the MySQL client interface.
To interact with RDS through your EC2 instance, install MySQL Server or just the MySQL client interface.
sudo apt-get install -y mysql-serverStop the local MySQL server. We won't be using it.
sudo /etc/init.d/mysql stopConnect to your RDS instance
mysql -h {rds_public_address} -P 3306 -u{username} -p{password}Do NOT use the following form. You will get a access denied.
mysql -u{username} -p{password} -h {rds_public_address} -P 3306
Update the JDBC settings in your application, recompile and test it.
Load Balancing Tomcat7
If you are planning to run multiple instances, read Setting up Lighttpd Load Balancer on EC2 Ubuntu or Setting up Nginx on EC2 Ubuntu.
Load Balancing Tomcat7
If you are planning to run multiple instances, read Setting up Lighttpd Load Balancer on EC2 Ubuntu or Setting up Nginx on EC2 Ubuntu.
Using Amazon SES to send emails
Amazon SES provides a easy way to send emails from your application. The strongest point of using SES is that it reduces the likelihood that your emails will be marked as spams by your ISPs.
You will need your AWS Access Keys and the SMTP Credentials.
Getting your AWS Access Keys
If you want to send email directly by using the Amazon SES API or the AWS SDK, you will need to use these keys.
In the AWS console, click on My Account/Console -> Security Credentials.
Obtain your access key id and the secret access key. (Scroll to the section called Access Credentials).
Getting the SMTP Credentials
Go to the Amazon SES console.
Click Create My SMTP Credentials.
Enter a new name for the IAM user or just use the default. Click Create.
Make sure you download the credentials or record it somewhere. You will NOT be able to see this again.
Testing Email Sending
In the SES console, click Verified Senders on the left sidebar.
Add a few email addresses by clicking on Verify a New Email Address.
Test sending a few emails and make sure you get them. Both senders and receivers need to be verified.
Request Production Access
Click in the form below. Usually, this process takes a day. It's better to request as early as possible.
https://portal.aws.amazon.com/gp/aws/html-forms-controller/contactus/SESProductionAccess2011Q3
Configuring your SMTP settings in your application
In the SES console, click SMTP Settings on the left sidebar.
You will need to configure your application with the following settings (also the SMTP credentials we set up above).
For my set up, I use Spring's email provider and configure my provider with the above settings.
That's it. Test sending your emails through emails.
If you want to directly access the Amazon SES API, look at Using the Amazon SES API to Send Email.
You will need your AWS Access Keys and the SMTP Credentials.
Getting your AWS Access Keys
If you want to send email directly by using the Amazon SES API or the AWS SDK, you will need to use these keys.
In the AWS console, click on My Account/Console -> Security Credentials.
Obtain your access key id and the secret access key. (Scroll to the section called Access Credentials).
Getting the SMTP Credentials
Go to the Amazon SES console.
Click Create My SMTP Credentials.
Enter a new name for the IAM user or just use the default. Click Create.
Make sure you download the credentials or record it somewhere. You will NOT be able to see this again.
Testing Email Sending
In the SES console, click Verified Senders on the left sidebar.
Add a few email addresses by clicking on Verify a New Email Address.
Test sending a few emails and make sure you get them. Both senders and receivers need to be verified.
Request Production Access
Click in the form below. Usually, this process takes a day. It's better to request as early as possible.
https://portal.aws.amazon.com/gp/aws/html-forms-controller/contactus/SESProductionAccess2011Q3
Configuring your SMTP settings in your application
In the SES console, click SMTP Settings on the left sidebar.
You will need to configure your application with the following settings (also the SMTP credentials we set up above).
Server Name: | email-smtp.us-east-1.amazonaws.com |
Port: | 25, 465 or 587 |
Use Transport Layer Security (TLS): | Yes |
Authentication: | Your SMTP credentials - see below. |
For my set up, I use Spring's email provider and configure my provider with the above settings.
That's it. Test sending your emails through emails.
If you want to directly access the Amazon SES API, look at Using the Amazon SES API to Send Email.
Subscribe to:
Posts (Atom)