1

sendgrid Web API を使用してメールを正常に送信していますが、カテゴリを x-smtpapi に追加できません。これが私のコードです:

function getHTML (strUrl,postData)
    Set xmlHttp = Server.Createobject("MSXML2.ServerXMLHTTP")
    xmlHttp.Open "POST", strUrl, False
    xmlHttp.setRequestHeader "User-Agent", "asp httprequest"
    xmlHttp.setRequestHeader "content-type", "application/x-www-form-urlencoded"
    'xmlHttp.AddHeader "category", "web"         
    xmlHttp.Send postData

    getHTML = xmlHttp.responseText
    xmlHttp.abort()
    set xmlHttp = Nothing   
end function

Response.Write("test->" & getHTML("https://sendgrid.com/api/mail.send.json","api_user=myusername&api_key=mykey&to=soneone@somemail.com&subject=test-1 msg&html=this is test message&from=info@zyxxxz.com&category={testweb}"))
Response.End()

ここでいくつかのドキュメントをチェックしました

しかし、カテゴリを追加する方法が見つかりませんでした。

編集

Response.Write("test->" & getHTML("https://sendgrid.com/api/mail.send.json","api_user=user&api_key=key&to=somemail@somemail.com&subject=test-1 msg&html=this is test message&from=info@xyzzz.com&x-smtpapi={"category":"testCategory"}"))

JSONを投稿する必要があります。二重引用符を付けないと、x-smtpapi={"category":"testCategory"}" JSON パーサーはそれを解析できません!

4

1 に答える 1

1

ASP では二重引用符がエスケープされます。

元。

#Invalid
str = " She said "Hello World" to the whole group"

#valid
str = " She said ""Hello World"" to the whole group"

したがって、これはうまくいくはずです:

Response.Write("test->" & getHTML("https://sendgrid.com/api/mail.send.json","api_user=user&api_key=key&to=somemail@somemail.com&subject=test-1 msg&html=this is test message&from=info@xyzzz.com&x-smtpapi={""category"":""testCategory""}"))
于 2013-04-30T10:50:32.330 に答える