Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Setting up Rails 3.2 for sending emails using Amazon's Simple Email Service (SES) is easy. <strong>You do not require any additional gem</strong> or monkey patching to make it work.</p> <p>SES supports both STARTTLS over SMTP as well as TLS/SSL. The following demonstrates how to set up Rails for STARTTLS with SES.</p> <p><strong>Prerequisites</strong></p> <ol> <li><p>If you are running rails Mac OS X, you may need to configure OpenSSL for Ruby correctly before you can use STARTTLS. If you are using Ruby 1.9.3 and RVM, here is one way to do this:</p> <pre><code>rvm pkg install openssl rvm reinstall 1.9.3 --with-openssl-dir=$rvm_path/usr </code></pre></li> </ol> <p>If you do not do this, there is a possibility that Ruby will segfault when you try to send an email.</p> <ol start="2"> <li><p>Make sure you have verified your sender email address with AWS. You can only send emails with a verified email address as the sender. Go to the "Verified Senders" option on the left menu in AWS console for SES.</p></li> <li><p>Make sure you have the AWS SMTP user name and password for authentication. Go to the "SMTP Settings" option on the left menu in AWS console for SES to set this up. You will first be prompted to create an IAM user (default: ses-smtp-user) and then you will be shown the SMTP user and password, which look like usual AWS key and secret. Note that the IAM user, i.e., ses-smtp-user is <strong>not</strong> the SMTP user that you will be using for authentication.</p></li> </ol> <p><strong>Configuring Rails</strong></p> <p>In config/environments/development.rb and config/environments/production.rb, add the following:</p> <pre><code> config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :address =&gt; "email-smtp.us-east-1.amazonaws.com", :port =&gt; 587, # Port 25 is throttled on AWS :user_name =&gt; "...", # Your SMTP user here. :password =&gt; "...", # Your SMTP password here. :authentication =&gt; :login, :enable_starttls_auto =&gt; true } </code></pre> <p><strong>Sending an email</strong></p> <p>This is it. Now you can go ahead and create a mailer and start sending emails for fun and profit!</p> <p><strong>Create a sample mailer</strong></p> <pre><code>rails g mailer user_mailer </code></pre> <p>In app/mailer/user_mailer.rb:</p> <pre><code> class UserMailer &lt; ActionMailer::Base # Make sure to set this to your verified sender! default from: "your@verifiedsender.com" def test(email) mail(:to =&gt; email, :subject =&gt; "Hello World!") end end </code></pre> <p>In views/user_mailer/test.erb:</p> <pre><code> A quick brown fox jumped over the lazy dog. </code></pre> <p>Now, launch the console and shoot off a test email:</p> <pre><code> rails c Loading development environment (Rails 3.2.1) 1.9.3p125 :001 &gt; UserMailer.test("your@email.com").deliver </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload