Mail gets send from smtp username setting not from "from" method in ActionMailer rails

232 views Asked by At

In user_mailer.rb

class UserMailer < ActionMailer::Base
  default from: "[email protected]"
  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 protected]",
  password: ENV["GMAIL_PASSWORD"]
}  

I get email from "[email protected]" why not from "[email protected]", waiting for clarification guys.

2

There are 2 answers

1
Waleed On BEST ANSWER

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 protected]' in development.rb file. Hence action mailer will ignore default from: "[email protected]" as it cannot authenticate it.

1
Allen Luce On

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 protected]" }