2013-04-30 39 views
1

我使用sendgrid web API成功發送郵件,但無法將類別添加到x-smtpapi。 這裏是我的代碼:sendgrid經典asp添加電子郵件類別

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&[email protected]&subject=test-1 msg&html=this is test message&[email protected]&category={testweb}")) 
Response.End() 

我查了一些文檔here

但我找不到任何方法來添加類別。

編輯

Response.Write("test->" & getHTML("https://sendgrid.com/api/mail.send.json","api_user=user&api_key=key&[email protected]&subject=test-1 msg&html=this is test message&[email protected]&x-smtpapi={"category":"testCategory"}")) 

我需要將它張貼JSON。如果我不把雙引號X-smtpapi = { 「類別」: 「testCategory」}」 JSON解析器不能解析它

回答

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&[email protected]&subject=test-1 msg&html=this is test message&[email protected]&x-smtpapi={""category"":""testCategory""}")) 
+3

我有一個困惑關於它!只是沒有檢查非常感謝!!!! – Mushfiq 2013-04-30 10:56:57

相關問題