1

我已经设置了一个 sendgrid 帐户并使用 cUrl 对其进行了测试:

curl -v -X POST https://api.sendgrid.com/api/mail.send.json
      -d "to=me@xxxxxxxxxx.com"      
      -d "from=noreply@xxxxxxxxxx.com"
      -d "subject=Sending with SendGrid is Fun"
      -d "html=and easy to do anywhere, even with CURL"
      -H "Authorization: Bearer xxxxxxxxxxxxxxxxxxx"

作品:

{"message":"success"}

MarkLogic 8现在我尝试在使用时做同样的xdmp.httpPost事情:

// query

var payload = xdmp.quote({ 
                            "to": "me@xxxxxxxxx.com",
                            "from" : "noreply@xxxxxxxxxx.com",
                            "subject" : "dingus",
                            "text" : "inhoud man"
                              }); 
xdmp.httpPost("https://api.sendgrid.com/api/mail.send.json",
         {
           "data" : payload,
           "headers" : {
           "Authorization" : "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
             "content-type" : "application/json"
           }
         });

失败:

{
"code": 400, 
"message": "Bad Request", 
"headers": {
"server": "nginx", 
"date": "Mon, 14 Mar 2016 09:55:23 GMT", 
"content-type": "application/json", 
"content-length": "68", 
"connection": "keep-alive", 
"x-frame-options": "DENY"
}
}
JSON Document 
{
"errors": [
"Empty from email address (required)"
], 
"message": "error"
}

一些搜索显示 sendgrid api 在确切的实现中相当挑剔,但也许我在这里遗漏了其他东西?

雨果

4

1 回答 1

1

好吧原来我在叫错树。

Sendgrid 需要一个表单输入(不是 JSON)

所以这有效:

var message = fn.concat('to=',msg_to,'&toname=',msg_toname,'&subject=Your activation&text=',msg_text,'&from=activation@xxxxx.com');

xdmp.httpPost("https://api.sendgrid.com/api/mail.send.json",
     {
       "data" : message,
       "headers" : {
         "Authorization" : "Bearer xxxxxxxxxxxxxxx",
         "content-type" : "application/x-www-form-urlencoded"
       }
     })
于 2016-03-15T09:03:33.053 回答