3
votes

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 [email protected] (54.4ms)
Date: Tue, 25 Aug 2015 12:15:15 -0700
From: [email protected]
Reply-To: [email protected]
To: [email protected]
Message-ID: <[email protected]>
Subject: Confirmation instructions
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<p>Welcome [email protected]!</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: '[email protected]'}
  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?

2
what mail server are you using?RoyTheBoy
Very good question. How / where can I get you this information? (Maybe that's my problem: I don't think I have setup a mail server).Thibaud Clement
Try mailcatcher. It makes dealing with emails in development much less of a PITA.max
What is your config.action_mailer.delivery_method specified?K M Rakibul Islam
Thanks for the tip. Is there any way to make emails work in development mode without using a third-party solution (i.e. only using Rails default configuration options)?Thibaud Clement

2 Answers

4
votes

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.

0
votes

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