Dynamic Developer Email Address

In the user model, each user belongs to a different domain / host. I want it to be different from an address based on a custom domain. Can I set this in the user model somewhere or how can I make the sender address dynamic according to the user's domain.

We set the default sender address in app/config/initializer/devise.rb as

 Devise.setup do |config| config.mailer_sender = SOME EMAIL ADDRESS end 
+7
ruby ruby-on-rails devise actionmailer
source share
3 answers

you can set mail.from based on email

 class UserMailer <ActionMailer::Base def notification_email(user) mail(to: example@example.com , from:user.email, ...) end 

This will change your default settings.

I think you can change these settings in config / initializers / devise.rb

  # Configure the class responsible to send e-mails. # config.mailer = "Devise::Mailer" config.mailer = "UserMailer" 

for your customized email program.

+1
source share

I came across this because I wanted to pull the from address from I18n, but the initializer worked before I18n was configured. This was the easiest solution for me:

 config.mailer_sender = Proc.new { I18n.t('mailers.from') } 
+7
source share

To use Mailer helper functions in Devise, extend your development email program and override methods / letters that need a different dynamic sender:

 class CustomDeviseMailer < Devise::Mailer def confirmation_instructions(record, token, opts={}) @token = token opts[:from] = "Dynamic Sender < dynamic@foo.com >" devise_mail(record, :confirmation_instructions, opts) end end 

And configure it in devise.rb :

 config.mailer = "CustomDeviseMailer" 

Note If you do not need a dynamic sender, just define the sender in devise.rb :

 config.mailer_sender = "Static sender < static@foo.com >" 
+2
source share

All Articles