我正在尝试创建一个自定义电子邮件标题以使用SendGrid api。
这是我正在做的-但不起作用:
class Mailman < ActionMailer::Base
default :from => "[email protected]"
def send_message(name, email, message)
@name = name
@email = email
@message = message
mail(:to => '[email protected]',
:from => email,
:subject => "Message from the site",
:headers['X-SMTPAPI'] => "category: Drip Email"
)
end
end
任何帮助表示赞赏。
谢谢,
亚当
最佳答案
您可以使用ActionMailer的#headers方法,我已编辑您的示例以显示如何:
class Mailman < ActionMailer::Base
default :from => "[email protected]"
def send_message(name, email, message)
@name = name
@email = email
@message = message
headers['X-SMTPAPI'] = '{"category": "Drip Email"}'
mail(
:to => '[email protected]',
:from => email,
:subject => "Message from the site"
)
end
end
另外,您也可以将哈希作为参数传递给方法#headers:headers {"SPECIFIC-HEADER-1" => "value", "ANOTHER-HEADER" => "and so..."}
我希望这可以为您提供帮助,如果不是这样,您始终可以查看rails指南:http://edgeguides.rubyonrails.org/action_mailer_basics.html。关于ruby-on-rails - 如何创建自定义电子邮件标题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7012203/