【发布时间】:2012-03-30 05:27:03
【问题描述】:
class SupportMailer < ActionMailer::Base
default :from => "email1@gmail.com"
def welcome_email(ticket)
case ticket.game
when "gameone"
@ticket = ticket
headers["Reply-to"] = "email1+#{ticket.token}@gmail.com"
headers["Return-Path"] = "email1+#{ticket.token}@gmail.com"
mail(:from => "email1@gmail.com", :to => ticket.email, :subject => "Welcome to 1 Support Ticket")
when "gametwo"
@ticket = ticket
headers["Reply-to"] = "email2+#{ticket.token}@gmail.com"
headers["Return-Path"] = "email2+#{ticket.token}@gmail.com"
mail(:from => "email2@gmail.com", :to => ticket.email, :subject => "Welcome to 2 Support Ticket")
when "gamethree"
@ticket = ticket
headers["Reply-to"] = "email3+#{ticket.token}@gmail.com"
header["Return-Path"] = "email3+#{ticket.token}@gmail.com"
mail(:from => "email3@gmail.com", :to => ticket.email, :subject => "Welcome to 3 Support Ticket")
end
end
end
我已经设置了我的默认值 :from,所以我不明白为什么我一直收到此消息,我也尝试通过标题设置它无济于事。
这是我的设置
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "gmail.com",
:user_name => "emailx@gmail.com",
:password => "password",
:authentication => "plain",
:enable_starttls_auto => true
}
我就这么称呼它,SupportMailer.support_response(@message).deliver
我该如何解决这个问题?
【问题讨论】:
-
标题绝对不需要;代码看起来正确,在您的情况下,
default :from被mail方法调用中的值覆盖。我会看看上游的交货地点!方法被调用,或者可能在环境文件中。错误来自交付后的第一个测试! smtp 模块中的方法。 -
我查看了我的控制器。看起来不错。我的配置看起来不错。我会发布它们
-
我已经在
headers "return-path" => "email1@gmail.com"方法中添加了这一行,现在它在抱怨At least one recipient (To, Cc or Bcc) is required to send a message,看起来mail(...)没有获取它的参数。 -
嗯——我用我的 gmail 帐户进行了测试,并举了一个简单的例子。也许我看到了问题:我看到的所有建议都建议从环境文件之一定义配置(我把我的放在
app/config/environments/development.rb中只是为了测试。它开始config.action_mailer.raise_delivery_errors = trueconfig.action_mailer.delivery_method = :smtpconfig.action_mailer.smtp_settings = {...也许这个是问题吗?否则,我会说:简化——去掉所有不重要的东西。
标签: ruby-on-rails-3 actionmailer ruby-on-rails-3.2 return-path