我正在尝试让我从 Ruby on Rails 应用程序通过 Gmail 发送的电子邮件来自 Ben
。
目前,当电子邮件到达(单独的、不相关的)Gmail 帐户时,收件箱中的发件人部分有 ben
。
这是我的设置:
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
下面是 Gmail 中的电子邮件设置:
最佳答案
在 :from 部分,您实际上可以这样指定电子邮件地址:
:from => 'Ben <ben@my_example.com>'
关于ruby-on-rails - 为什么我不能在我的 Rails 应用程序中使用 Gmail 正确设置 FROM 名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6224807/