继续获取发送消息所需的发件人(Return-Path,Sender或From)

时间:2012-03-13 19:01:53

标签: ruby-on-rails-3 actionmailer ruby-on-rails-3.2 return-path

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

我已经设置了默认值:来自,所以我不知道为什么我一直收到这条消息,我也试图通过标题来设置它无济于事。

这是我的设置

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

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:3)

我注意到你没有case语句的默认情况。如果你永远不会在Mailer类的方法中调用“mail”方法,那么你将得到那个错误。尝试将您的case语句移动到您调用SupportMailer的位置,也许每种情况都有方法。这样你就不会打电话给SupportMailer,除非你已经确定了正确的票务游戏。