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
build_resource
if resource.save
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
UserMailer.welcome_email(resource).deliver
sign_in(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
expire_session_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
respond_with resource
end
end
in that line
UserMailer.welcome_email(resource).deliver
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!")
end
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;
boundary="--==_mimepart_4f872de0883d4_1805f3fdba4834cd49281a";
charset=UTF-8
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
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.rblike this:If you’ve done this, ensure that your controller is the one being used. Furthermore, regarding
sendmailspecifically, I haven’t tried using it yet, but assuming thatsendmailuses 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 editingconfig/environments/development.rb: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:
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:
And edit
config/application.rb: