Do not try to access current_user from inside Mailer. Instead, pass the user to the mailer method. For instance,
class WelcomeMailer < ActionMailer::Base def welcome_email(user) mail(:to => user.email, :subject => 'Welcome') end end
To use it from the controller, where you have access to current_user :
WelcomeMailer.welcome_email(current_user).deliver
From the model:
class User < ActiveRecord::Base after_create :send_welcome_email def send_welcome_email WelcomeMailer.welcome_email(self).deliver end end
source share