从 Rails 应用程序发送邮件时指定"from"电子邮件地址



我正在使用gmail来管理rails应用程序域的电子邮件。

比如说,谷歌账户,account_owner@gmail.com

但"发件人"的电子邮件地址应该是,info@mysite.com

当我按以下方式配置smtp_settings时,会发送电子邮件,但"发件人"电子邮件地址为account_owner@gmail.com.我希望它是info@mysite.com,但如果我将:user_name更改为info@mysite.com和它的密码,我的应用程序似乎发送了电子邮件,但从来没有收到。我怎样才能做到这一点?

ActionMailer::Base.smtp_settings = {
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :domain               => "gmail.com",
  :user_name            => "account_owner@gmail.com",
  :password             => "thepassword",
  :authentication       => "plain",
  :enable_starttls_auto => true
}

通过Gmail发送邮件时,无法更改"发件人"地址。(除非你已经将该帐户配置为具有其他"作为发送"地址,尽管我从未测试过它)

我建议尝试为您的域免费托管Gmail,或者使用像Mandrill.com 这样的第三方服务

您不应该在smtp_settings中将其指定为:user_name。相反,您应该像这样设置:from选项:

ActionMailer::Base.default :from => 'info@mysite.com'

或者,您可以在发送电子邮件时设置发件人地址:

mail(:to => 'info@theirsite.com', :from => 'info@mysite.com' :subject => '...')

相关内容

最新更新