Take the 2-minute tour ×

im using devise and im trying to send a welcome email after someone signs up using actionmailer.

i overwrote the Registration controller on devise with...

  def create

    if resource.save
      if resource.active_for_authentication?
        set_flash_message :notice, :signed_up if is_navigational_format?


        sign_in(resource_name, resource)
        respond_with resource, :location => after_sign_up_path_for(resource)
        set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
        respond_with resource, :location => after_inactive_sign_up_path_for(resource)
      clean_up_passwords resource
      respond_with resource

in that line


i call my user_mailer.rb

  default :from => "blink@gmail.com"

  def welcome_email(user)
    @user = user
    @url = "http://example.com/login"
    mail(:to => user.email, :submit => "Welcome YEAH!")     

i have a view under app/views/user_mailer/welcome_email.text.erb

in my initializers folder i have a setup_mail.rb

ActionMailer::Base.smtp_settings = {
    :address                => "smtp.gmail.com",
    :port                   => 587,
    :domain                 => "gmail.com",
    :user_name              => "blink@gmail.com",
    :password               => "example",
    :authentication     => "plain",
    :enable_starttls_auto   => true

in my development.rb i have...

config.action_mailer.delivery_method = :sendmail
config.action_mailer.perform_deliveries = true

i am super stumped why this hasn't been working. ive written an older project and i got the action mailer to work. the code right now is nearly identitcal to my old project. the exception is that im using devise now.

in my terminal window, when i run 'rails server', on that window it also says...

Sent mail to blink@gmail.com (140ms)
Date: Thu, 12 Apr 2012 12:32:48 -0700
From: blink@gmail.com
To: blink@gmail.com
Message-ID: <4f872de096f4e_1805f3fdba4834cd493153@spiderman.local.mail>
Subject: Welcome email
Mime-Version: 1.0
Content-Type: multipart/alternative;
Content-Transfer-Encoding: 7bit
submit: Welcome YEAH!

after a user signs up. i dont think its really sending though. my gmail never gets it and its not in my spam. could it be something with devise's mailer/views? but im explicitly using UserMailer in the controller, which is why i overwrote it

ive been stuck for days! help would be greatly appreciated. thanks a bunch

share|improve this question

2 Answers 2

up vote 2 down vote accepted

First of all, you must ensure that you tell devise were to look for your controller (since you've subclassed it, I assume). You can do this by editing config/routes.rb like this:

# config/routes.rb
devise_for :users, :controllers => {:registrations => "registrations"}

If you've done this, ensure that your controller is the one being used. Furthermore, regarding sendmail specifically, I haven't tried using it yet, but assuming that sendmail uses your host OS's internal mail agent, and that you are under a dynamic IP address (which ISPs give to its users upon connection), I believe that mail providers like GMail will block your message, as they do not allow dynamic IPs to serve as mail providers. They do this for security purposes mainly. Perhaps you can check this by editing config/environments/development.rb:

# config/environments/development.rb
config.action_mailer.raise_delivery_errors = true

to see if there is something going on under the hood. If that doesn't help that much (and since what you are effectively trying to do is sending email using a valid mail account - given your ActionMailer settings), you can use SMTP delivery instead of sendmail, along with the configuration you have, editing this line:

# config/environment/development.rb
config.action_mailer.delivery_method = :smtp

in your initializer which will, in fact, send the email through the account specified to the designated recipients.

As a final (off topic) suggestion I suggest you to use Rails Observers, in which case you don't need to overwrite Devise's registrations controller. This would make your life much simpler, DRY and follow convention over configuration's philosophy. You could then just create an Observer like this:

# app/observers/user_observer.rb
class UserObserver < ActiveRecord::Observer
  def after_create(user)

And edit config/application.rb:

config.active_record.observers = :user_observer
share|improve this answer
unbelievable. i honestly thought i tried changing it to smtp. i must have done it somewhere else. it works also by not configuring it, as i guess it defaults to smtp (at least based on how i set it). thank you so much it. i much appreciate it! –  Sasha Apr 13 '12 at 1:05

Have you tried

config.action_mailer.delivery_method = :smtp

And have a look at mailcatcher for testing email in development, I find it much easier than actually sending the mail.

share|improve this answer
thank you! yes smtp was the way to go! –  Sasha Apr 13 '12 at 1:05

Your Answer


