ActionMailer Settings for Gmail with Rails 3.2 Running on Amazon EC2 Instance
Background
Attempting to resolve an issue with configuring Gmail for ActionMailer in Rails 3.2.x running on an Ubuntu instance on Amazon EC2. The app works with Nginx + Passenger.
Setting is done as follows
File: config / environment / production.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:authentication => :plain,
:user_name => "<username>@gmail.com",
:password => "<secret-word>",
:enable_starttls_auto => true
}
The email works with a google account verified by web login and sending a test message.
The controller initiates the dispatch using the method:
email_list_controller.rb
def email_test_send
@email = params[:email]
@message = Message.find(params[:id])
@member = Member.find_by_last_name("Bloggs")
MemberMailer.delay.all_member_email(@member.email, @message)
redirect_to messages_path, :notice => "Test Email has been sent."
end
with the MemberMailer class defined as:
class MemberMailer < ActionMailer::Base
default from: "blah@gmail.com"
default cc: "blah1@gmail.com, blah2@gmail.com"
default content_type: "text/html"
# send a message to member
def all_member_email(email, message)
@message = message
mail(:to => email, :subject => message.subject)
end
end
The system uses a Delayed_Job Gem for background processing, and the submission has been tested with and without background job processing .;
Result
The problem is that the message is not being sent and the following happens:
-
Output to production.log (with log_level set to DEBUG
Processing by EmailListController # email_test_send as HTML Parameters: {"utf8" => "✓", "authenticity_token" => "D5ZCb + Ha63WbPmd47 / 1 / P3rpFJFiSbnrYya + YaSmBic =", "email" => " blah@gmail.com ", "commit" => "Submit", "id" => "1", "method" => "post"}
-
Message not sent
-
Google account is sent does not display information about outbox messages.
-
Verified that EC2 server can connect to Google SMTP server via telnet 587
-
Examined other StackOverflow questions like Setting up a Gmail account to work with ActionMailer in Rails 3
-
There are no database errors in the delayed_jobs table.
So stuck for any other areas to look at? I tried restarting the server to ensure a clean load of the config files, etc., but no luck.
source to share