javascript - Mailgun HTTP 错误代码 400 错误请求

标签 javascript http google-cloud-functions mailgun

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

Bad Request - Often missing a required parameter 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);

我在我的应用程序中调用这个函数,这是应用程序内部的代码:

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);
                    })
  }

我已经关注了 firebase API https://documentation.mailgun.com/en/latest/quickstart-sending.html#send-via-api 我不知道缺少哪些参数,因为我只是复制并粘贴了他们的示例代码

最佳答案

我改变了这个

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

收件人:

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

关于javascript - Mailgun HTTP 错误代码 400 错误请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48910047/

相关文章:

javascript - 如何在同一数组索引处插入具有先前插入项的新数组值

apache - 为什么 http 和 https 协议(protocol)指向不同的目录?

javascript - express 4.x 将 http 重定向到 https

php - PHP cURL 可以在单个请求中检索响应 header 和正文吗?

javascript - 尝试使用类来保持我的代码干净 - 不起作用

javascript - Firebase 检查节点是否存在返回 true 或 false

javascript - 使用 RxJs 将多个回调返回映射到 observable

javascript - 如何画一条线到从 Angular 派生的点?

firebase - 使用Firebase云功能实现发送电子邮件

javascript - 使用 Canvas 创建桌面通知图像,只有一个图像来自背景页面