I had some trouble integration ActionMailer into my Rails app so I tried to make a very simple example to test it out. I followed the ActionMailer guide to do so.
When the user visits /test
it should send an email to them and redirect them to the root. The log below seems to indicate that the message was sent without error but I'm not receiving anything in my inbox.
log when user visits /test
UserMailer#welcome: processed outbound mail in 16.5ms
Sent mail to me@gmail.com (6.5ms)
Date: Fri, 15 Aug 2014 14:38:26 +0800
From: itsupport@mydomain.com
To: me@gmail.com
Message-ID: <53edaae23b766_58de3fe95291a584391d@MacBook-Pro.local.mail>
Subject: Welcome
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
#message content correctly formatted
Redirected to http://localhost:3000/
Completed 302 Found in 29ms (ActiveRecord: 1.2ms)
development.rb
config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'mydomain.com',
:user_name => 'itsupport@mydomain.com',
:password => 'password',
:authentication => 'plain',
:enable_starttls_auto => true }
usermailer.rb
class UserMailer < ActionMailer::Base
default from: "itsupport@mydomain.com"
def welcome(user)
@user = user
mail(to: user.email, subject: 'Welcome')
end
end
lessons controller
def sendemail
UserMailer.welcome(current_user).deliver
redirect_to root_path
end
routes.rb
get 'test' => 'lessons#sendemail'
I've tried
- Checking Spam
- Changing the authentication on 'plain' and 'login'
- Explicitly starting the server in development mode
- Not specifying the 'from' field
- Having domain: as both my domain and as gmail.com (different answers use these interchangeably)
The Message ID in the log suggests it's being sent from my personal computer instead of gmail - am I completely wrong or is this an issue?
If you can help me in getting these emails received it'd me much appreciated!
EDIT - I've pushed the app to Heroku to get around the possibility of gmail not liking email sent from localhost as some answers have suggested. My Heroku logs state that mail was sent to me@gmail.com but still nothing shows up in my inbox...