我相信我已经关注了SendGrid网站上的文档,但到目前为止,当我收到我通过他们的API发送的电子邮件时,它永远不会替换我在x-smtpapi标头中指定的替换。我正在使用HTTParty发送这样的请求:
HTTParty.post(Sendgrid::Postman.api_url, {
:query => params.merge({ "api_user" => @config[:api_user], "api_key" => @config[:api_key] }),
:headers => headers, :format => :json
})
{"from"=>"noreply@foo.com", "text"=>"Happy Holidays -first_name- -last_name-,\nI hope this message finds you in good health and high spirits.", "to"=>["foo@gmail.com"], "subject"=>"foo"}
标题看起来像这样:
{"X-SMTPAPI"=>"{\"sub\": {\"-first_name-\": [\"Foo\"], \"-email-\": [\"foo@gmail.com\"], \"-login-\": [\"heavysixer\"], \"-last_name-\": [\"Bar\"]}, \"to\": [\"foo@gmail.com\"]}"}
邮件总是成功发送,但当邮件到达收件箱时,应该替换的值仍然显示为-first_name-& -last_name-
我错过了什么?我现在一直在忙着解决这个问题吗?
更新: 根据下面的建议,我试图将x-smtpapi参数推入表格帖子但我得到了相同的结果。我的帖子的查询字符串现在如下所示:
params = {"api_user" => 'foo', "api_key" => 'bar', "from"=>"noreply@foo.com", "text"=>"Happy Holidays -first_name- -last_name-,\nI hope this message finds you in good health and high spirits.", "to"=>["foo@gmail.com"], "subject"=>"foo", "x-smtpapi"=>{"sub"=>{"-first_name-"=>["foo"], "-email-"=>["foo@gmail.com"], "-login-"=>["foo"], "-last_name-"=>["bar"]}}}
HTTParty.post(Sendgrid::Postman.api_url, :query => params, :format => :json)