【问题标题】:Mailgun HTTP error code 400 Bad RequestMailgun HTTP 错误代码 400 错误请求
【发布时间】:2018-02-21 15:48:44
【问题描述】:

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

我在我的应用程序中将此函数称为应用程序内的代码:

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 我不知道缺少哪些参数,因为我只是复制并粘贴了他们的示例代码

【问题讨论】:

    标签: javascript http google-cloud-functions mailgun


    【解决方案1】:

    我改变了这个

    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!'
        };

    【讨论】:

      猜你喜欢
      • 2017-12-14
      • 2019-12-22
      • 1970-01-01
      • 1970-01-01
      • 2021-04-20
      • 1970-01-01
      • 1970-01-01
      • 2016-11-18
      • 1970-01-01
      相关资源
      最近更新 更多