sendgrid在经典的asp添加电子邮件类别

时间:2013-04-30 09:53:56

标签: asp-classic asp.net-web-api sendgrid

我正在使用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()

我查了一些文档here

但我找不到任何方法来添加类别。

修改

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解析器无法解析它!

1 个答案:

答案 0 :(得分: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""}"))