3

First, let me specify that I am aware that ActionMailer does NOT send emails by default in development mode.

Also, I took a look at similar questions, and none of them was relevant to my situation.

So, here we go:

  1. I am following this Site Point tutorial by Ilya Bodrov-Krukowski, from March 26, 2015 in order to install and setup Devise on my Rails 4 app.

  2. Because we activated Devise's confirmable module, I need to send emails in development to allow users who signup to activate their account and login.

  3. Whenever I create a new user (through http://localhost:3000/users/sign_up), I do get the following alert:

A message with a confirmation link has been sent to your email address. Please follow the link to activate your account.

  1. However, I never actually receive the email with the confirmation link.

——————————

UPDATE

In my development.log file, I can see that the email was "sent":

Devise::Mailer#confirmation_instructions: processed outbound mail in 172.1ms

Sent mail to hello@mydomain.com (54.4ms)
Date: Tue, 25 Aug 2015 12:15:15 -0700
From: contact@anotherdomain.com
Reply-To: contact@anotherdomain.com
To: hello@mydomain.com
Message-ID: <55dcbec3a1ef8_33b93fcffc4988f493685@XXXXXX.local.mail>
Subject: Confirmation instructions
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<p>Welcome hello@mydomain.com!</p>

<p>You can confirm your account email through the link below:</p>

<p><a href="http://localhost:3000/users/confirmation?confirmation_token=ZsL_iQVxfDQd7mB1RkGf">Confirm my account</a></p>

  [1m[35m (0.8ms)[0m  commit transaction
Redirected to http://localhost:3000/
Completed 302 Found in 560ms (ActiveRecord: 1.7ms)

And, when I copy and paste the link from the log into my browser, then I get the following alert:

Signed in successfully.

So, it seems the only thing that is not working is the actual sending / receiving of the email.

——————————

As recommended in the tutorial, I followed Rails documentation regarding ActionMailer configuration and here is what I have in my config/environments/development.rb file:

config.action_mailer.delivery_method = :sendmail
  # Defaults to:
  # config.action_mailer.sendmail_settings = {
  #   location: '/usr/sbin/sendmail',
  #   arguments: '-i -t'
  # }
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default_options = {from: 'hello@mydomain.com'}
  config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

Obviously, I am missing something, but I cannot figure out what (I am very, very junior with Rails).

Any idea?

Thibaud Clement
  • 6,607
  • 10
  • 50
  • 103

2 Answers2

4

Mail is not sent in development by default. To enable this you have to set config.action_mailer.perform_deliveries = true in development.rb file which I see you already have.

You may also have to enable config.action_mailer.raise_delivery_errors = true to raise delivery errors. That way, you will be able to see if there are any errors in the email delivery process.

Also, double check your default from if that has a valid email.

Also try switching the delivery method to sendmail:

config.action_mailer.delivery_method = :sendmail

This should solve your issue.

K M Rakibul Islam
  • 33,760
  • 12
  • 89
  • 110
  • 1
    Thanks. As mentioned in the question, I already have `config.action_mailer.delivery_method = :sendmail` and `config.action_mailer.raise_delivery_errors = true` defined. Is there something else that could cause the issue? Is there any log I can pull to understand what is going wrong? – Thibaud Clement Aug 25 '15 at 19:23
  • 1
    Do you have `config.action_mailer.raise_delivery_errors = true` as well? Then it should show some error if there is any while delivering – K M Rakibul Islam Aug 25 '15 at 19:31
  • 1
    Yes, I do. You can see all my configuration for `config/environments/development.rb file` in the question. And I have no error. – Thibaud Clement Aug 25 '15 at 19:36
0

You need a mail server for Action Mailer to send emails. such as MailGun which has a free account and a gem which makes set up easy. mailgun_rails

RoyTheBoy
  • 648
  • 1
  • 6
  • 15