ben
ben

Reputation: 29797

Why can't I set the FROM name correctly using Gmail in my Rails app?

I am trying to get the emails I send through Gmail from my Ruby on Rails app to be from Ben.

Currently when the email arrives in a (seperate, non-related) Gmail account, in the Inbox it has ben in the from section.

Here are my settings:

setup_mail.rb

# my domain is my_example.com, and the email address I am sending from is ben@my_example.com
ActionMailer::Base.smtp_settings = {
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :domain               => "my_example.com",
  :user_name            => "ben@my_example.com",
  :password             => "my_password",
  :authentication       => "plain",
  :enable_starttls_auto => true
}
if Rails.env.development?
    ActionMailer::Base.default_url_options[:host] = "localhost:3000" 
else    
    ActionMailer::Base.default_url_options[:host] = "my_example.com"
end

report_mailer.rb

  def send_notification_email(notification_details)
    subject = "testing_email"
    mail(:to => notification_details[:email], :subject => subject, :from => "Ben")  
  end

And here are the email settings in Gmail: enter image description here

Upvotes: 3

Views: 343

Answers (2)

Dhruva Sagar
Dhruva Sagar

Reputation: 7307

In the :from part you can actually specify the email address this way :

:from => 'Ben <ben@my_example.com>'

Upvotes: 4

Ryan Bigg
Ryan Bigg

Reputation: 107728

The :from key there is actually the email you're sending it from. GMail does not allow this to be overriden, as it can lead to abuse.

Upvotes: 2

Related Questions