1

我相信我已经关注了 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)
4

1 回答 1

1

Their documentation implies that x-smtpapi should be one of the posted parameters, not an http header.

于 2011-12-22T03:39:23.457 回答