1

In user_mailer.rb

class UserMailer < ActionMailer::Base
  default from: "email.1@gmail.com"
  def approved_mail(user)
    @user = user
    @greeting = "Hi"

    mail to: @user.email
  end
end  

And in development.rb

config.action_mailer.smtp_settings = {
  address: "smtp.gmail.com",
  port: 587,
  domain: "gmail.com",
  authentication: "plain",
  enable_starttls_auto: true,
  user_name: "email.2@gmail.com",
  password: ENV["GMAIL_PASSWORD"]
}  

I get email from "email.2@gmail.com" why not from "email.1@gmail.com", waiting for clarification guys.

roarfromror
  • 276
  • 1
  • 2
  • 11

2 Answers2

2

In the smtp_settings, we need to set the user_name and password if our mail server requires authentication.

In your case you have provided the authentication for 'email.2@gmail.com' in development.rb file. Hence action mailer will ignore default from: "email.1@gmail.com" as it cannot authenticate it.

Waleed
  • 766
  • 5
  • 4
  • means, 'from' default option in user_mailer.rb and 'smtp_settings > user_name' should be same - is my comment true or I'm lacking sufficient understanding – roarfromror Dec 02 '14 at 08:41
1

user_name in the smtp_settings only refers to the authentication name used to connect to the SMTP server.

Add this to your development.rb:

config.action_mailer.default_options = { from: "email.2@gmail.com" }
Allen Luce
  • 7,859
  • 3
  • 40
  • 53
  • Thanks for solution, but I should have received email from address specified in user_mailer.rb, so I want to know why line 'default from: "email.1@gmail.com"' in user_mailer.rb not working. – roarfromror Dec 02 '14 at 07:17