user984621
user984621

Reputation: 48443

Actionmailer - how can I set up "from" part?

This is my config file in /config/initializers/setup_mail.rb:

ActionMailer::Base.smtp_settings = {  
  :address              => "smtp.gmail.com",  
  :port                 => 587,  
  :domain               => "...something...",  
  :user_name            => "my_gmail_name",  
  :password             => "my_gmail_pass",
  :authentication       => "plain",  
  :enable_starttls_auto => true  
}

And this is the Mailer's class with method I use:

class Notifierpass < ActionMailer::Base
  default from: "[email protected]"

  def forgot_password(user)    
    @reset_password_link = reset_password_url(user.perishable_token)

    mail(:from => "[email protected]", :to => user.email, :subject => "New passwordt")  
  end
end

The sending emails is working, my problem is, that in the email's field From is always my_user_name instead [email protected].

Where is the problem? Why is still used my gmail name?

Upvotes: 0

Views: 109

Answers (2)

dennis
dennis

Reputation: 2020

When you make a connection to the smtp server of gmail (like in your config) the authentication_information is already assigned because you will send an email using a certain user_id wich has a known email address. therefor google will not accept any :from => "value" but it will fit the :from parameter with the email returned by the auth_info.

Hope this helped you

Upvotes: 0

sammyd
sammyd

Reputation: 893

GMail will only let you send emails from your account, or other email addresses you have correctly configured. To send from an alternative email address you need to add it in the Gmail settings. You can only add addresses that you can already receive from.

Upvotes: 1

Related Questions