如何创建自定义电子邮件标题 [英] How to create custom email headers
本文介绍了如何创建自定义电子邮件标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建自定义电子邮件标头以使用 SendGrid api.
I'm trying to create a custom email header to use the SendGrid api.
这是我正在做的 - 但它不起作用:
Here's what I'm doing - but its not working:
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 方法,我已经编辑了你的例子来展示如何:
You can use the #headers method of ActionMailer, I've edited your example to show how:
class Mailman < ActionMailer::Base
default :from => "info@sample.com"
def send_message(name, email, message)
@name = name
@email = email
@message = message
headers['X-SMTPAPI'] = '{"category": "Drip Email"}'
mail(
:to => 'info@sample.com',
:from => email,
:subject => "Message from the site"
)
end
end
或者,您也可以将散列作为参数传递(传递给方法 #headers):
Alternatively, you can pass a hash as an argument (to the method #headers) too:
headers {"SPECIFIC-HEADER-1" => "value", "ANOTHER-HEADER" => "and so..."}
我希望这可以帮助您,如果不能,您可以随时查看 Rails 指南:http:///edgeguides.rubyonrails.org/action_mailer_basics.html.
I hope this can help you, and if not you always can check the rails guides: http://edgeguides.rubyonrails.org/action_mailer_basics.html.
这篇关于如何创建自定义电子邮件标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文