我试图创建一个自定义的邮件头来使用SendGrid api.
这是我正在做的 – 但它不工作:
class Mailman < ActionMailer::Base default :from => "info@sample.com" def send_message(name,email,message) @name = name @email = email @message = message mail(:to => 'info@sample.com',:from => email,:subject => "Message from the site",:headers['X-SMTPAPI'] => "category: Drip Email" ) end end
任何帮助赞赏.
谢谢,
亚当
解决方法
您可以使用ActionMailer的#headers方法,我已经编辑了您的示例来显示如何:
class Mailman < ActionMailer::Base default :from => "info@sample.com" def send_message(name,message) @name = name @email = email @message = message headers['X-SMTPAPI'] = '{"category": "Drip Email"}' mail(:to => 'info@sample.com',:subject => "Message from the site" ) end end
或者,您可以传递哈希作为参数(对方法#headers):
headers {"SPECIFIC-HEADER-1" => "value","ANOTHER-HEADER" => "and so..."}
我希望这可以帮助你,如果不是,你总是可以检查导轨:http://edgeguides.rubyonrails.org/action_mailer_basics.html.