ruby-on-rails – 如何创建自定义邮件头

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 如何创建自定义邮件头前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图创建一个自定义邮件头来使用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.

原文链接:https://www.f2er.com/ruby/272834.html

猜你在找的Ruby相关文章