Skip to content

Instantly share code, notes, and snippets.

@chrisroos
Last active January 25, 2022 20:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chrisroos/6b32b07aefa010526f7e5cfe58d61978 to your computer and use it in GitHub Desktop.
Save chrisroos/6b32b07aefa010526f7e5cfe58d61978 to your computer and use it in GitHub Desktop.

Testing Rails ActionMailer and AWS SES

I added two verified email addresses to AWS SES so that I could send emails from/to them while in the SES Sandbox.

UserMailer

class UserMailer < ApplicationMailer
  default from: 'accounts+aws-ses@gofreerange.com'

  def welcome_email
    mail(to: 'chris.roos@gofreerange.com', subject: 'Welcome to My Awesome Site')
  end
end

ActionMailer config

config.action_mailer.smtp_settings = {
  address: 'email-smtp.eu-west-1.amazonaws.com',
  port:	25, # or 465 or 587
  enable_starttls_auto: <boolean>,
  tls: <boolean>, 
  ssl: <boolean>, 
  user_name: '<username>',
  password: '<password>'
}

Test command

$ rails r "UserMailer.with({}).welcome_email.deliver_now"

Result summary

Ports 25 and 587 require enable_starttls_auto to be set to true, and for tls and ssl to be set to false.

Port 465 ignores enable_starttls_auto and requires either tls or ssl to be set to true.

This relates to the Connecting to the Amazon SES SMTP Endpoint documentation which says that SES supports STARTTLS on ports 25, 587 and 2587, and supports TLS on ports 465 and 2465.

Results

Port Enable STARTTLS Auto TLS SSL Outcome
25 True True True OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol
25 True True False OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol
25 True False True OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol
25 True False False Email sent correctly
25 False False False Net::SMTPAuthenticationError: 530 Must issue a STARTTLS command first
25 False True True OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol
25 False True False OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol
25 False False True OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol
465 True True True Email sent correctly
465 True True False Email sent correctly
465 True False True Email sent correctly
465 True False False Net::ReadTimeout: Net::ReadTimeout
465 False False False Net::ReadTimeout: Net::ReadTimeout
465 False True True Email sent correctly
465 False True False Email sent correctly
465 False False True Email sent correctly
587 True True True OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol
587 True True False OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol
587 True False True OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol
587 True False False Email sent correctly
587 False False False Net::SMTPAuthenticationError: 530 Must issue a STARTTLS command first
587 False True True OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol
587 False True False OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol
587 False False True OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment