开发者

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               => 开发者_如何学C"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:

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


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

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜