Nor*_*and 23 ruby-on-rails sendgrid
我正在尝试创建自定义电子邮件标头以使用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
Run Code Online (Sandbox Code Playgroud)
任何帮助赞赏.
谢谢,亚当
Ric*_*ano 56
你可以使用ActionMailer的#headers方法,我编辑了你的例子来说明如何:
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
Run Code Online (Sandbox Code Playgroud)
或者,您也可以将哈希作为参数传递给方法#headers:
headers {"SPECIFIC-HEADER-1" => "value", "ANOTHER-HEADER" => "and so..."}
Run Code Online (Sandbox Code Playgroud)
我希望这可以帮助你,如果不是,你总是可以查看rails指南:http://edgeguides.rubyonrails.org/action_mailer_basics.html.
我使用下面的代码,工作正常,只需将哈希转换为json to_json
headers['X-SMTPAPI'] = {
category: "Weekly Newsletter",
unique_args: { user_id: user.id }
}.to_json
Run Code Online (Sandbox Code Playgroud)