Mailgun HTTP错误代码400 Bad Request

时间:2018-02-21 15:48:44

标签: javascript http google-cloud-functions mailgun

Mailgun根据他们的文档意味着给我一个400的HTTP代码

  

错误请求 - 通常缺少必需参数   https://documentation.mailgun.com/en/latest/api-intro.html#errors

我在firebase云功能中有邮件发送功能,这是云功能



app.post('/sendMail', (req, res) => {

    const data = {
        from: 'Excited User <me@samples.mailgun.org>',
        to: 'email, apikey',
        subject: 'Hello',
        text: 'Testing some Mailgun awesomness!'
    };

    mailgun.messages().send(data, function (error, body) {
        if(error){
            console.log(error);
            res.send(error)
        }
        console.log(body);
        res.send('sent email!')
    });
});

exports.app = functions.https.onRequest(app);
&#13;
&#13;
&#13;

我在我的应用程序中调用此函数,这是app中的代码:

&#13;
&#13;
sendEmail(){
    let url  = `URL to my cloud function`;
    let params: URLSearchParams = new URLSearchParams();

 let data = {
      from: 'Excited User <me@samples.mailgun.org>',
      to: 'myEmail , apiKey',
      subject: 'Hello',
      text: 'Testing some Mailgun awesomness!'
};
    
    return this.http.post(url,data)
                    .toPromise()
                    .then(res=>{
                      console.log(`Res:`,res);

                    })
                    .catch(err => {
                      console.log('Error',err);
                    })
  }
&#13;
&#13;
&#13;

我已关注firebase API https://documentation.mailgun.com/en/latest/quickstart-sending.html#send-via-api 我不知道什么参数丢失,因为我刚刚复制并粘贴了他们的示例代码

1 个答案:

答案 0 :(得分:0)

我改变了这个

&#13;
&#13;
const data = {
        from: 'Excited User <me@samples.mailgun.org>',
        to: 'email, apikey',
        subject: 'Hello',
        text: 'Testing some Mailgun awesomness!'
};
&#13;
&#13;
&#13;

致:

&#13;
&#13;
const data = {
        from: 'me@samples.mailgun.org',
        to: 'email',
        subject: 'Hello',
        text: 'Testing some Mailgun awesomness!'
    };
&#13;
&#13;
&#13;