【问题标题】:ActionMailer Rails 3ActionMailer Rails 3
【发布时间】:2013-07-29 23:29:21
【问题描述】:

这是我第一次使用 ActionMailer。我很难设置发件人电子邮件。 这是我的 development.rb :

config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address:              'smtp.gmail.com',
    port:                 587,
    user_name:            'foo',
    password:             'mypass',
    authentication:       'plain',
    enable_starttls_auto: true  
}
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true

这是我的 feedback_mailer.rb :

class FeedbackMailer < ActionMailer::Base
  def feedback_email(feedback, setting_configuration)
    @feedback = feedback
    @setting_configuration = setting_configuration
    mail(to: @setting_configuration.value, :from => feedback.email, subject: @feedback.inquiry_type )
  end
end

但发件人电子邮件仍然是 foo@gmail.com。 我可以使用 smtp 设置发件人的电子邮件吗?或者我必须使用sendmail?我尝试使用:sendmail,而不是 smtp,但我有这个错误:

Errno::ENOENT - No such file or directory - /usr/sbin/sendmail -i -t -f 

我应该在 sendmail 中设置什么?我试过用谷歌搜索它和一切,但没有任何效果。如果有人可以提供帮助,我会很高兴。谢谢

【问题讨论】:

    标签: ruby-on-rails-3 smtp actionmailer


    【解决方案1】:

    你所拥有的看起来是正确的。邮件调用中的“发件人”参数应设置电子邮件中的电子邮件地址。我们在 Heroku 上使用 Sendgrid,它可以工作。这让我怀疑谷歌可能正在用帐户持有人的电子邮件地址替换它。也许使用其他电子邮件服务对其进行测试,看看您是否有更好的运气。

    【讨论】:

    • 我在 Google 的网站上找不到任何可以确认的信息,但我确实找到了 stackoverflow.com/questions/5784936/actionmailer-from-setting。实际上,Google 似乎确实忽略了 from 字段。如果您使用 Heroku,Sendgrid 很容易设置,免费版本可能就是您所需要的。祝你好运。
    • 是的,你是对的。谷歌替换了 from 字段。谢啦!我现在正在考虑使用 Sendgrid
    猜你喜欢
    • 2011-07-22
    • 2011-06-24
    • 2013-04-09
    • 2011-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多