Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js mailgun不发送返回未定义数据的电子邮件_Node.js_Angular_Http_Mailgun - Fatal编程技术网

Node.js mailgun不发送返回未定义数据的电子邮件

Node.js mailgun不发送返回未定义数据的电子邮件,node.js,angular,http,mailgun,Node.js,Angular,Http,Mailgun,我正在尝试使用Angular 4、nodejs、mailgun js和mailgun在注册流上实现一个简单的电子邮件确认。问题在于邮枪发送: mailgun.messages().send(data, function(error, body) { console.log(body); }); 正在超时,前端出现以下错误: POST http://localhost:3000/users/sendMail net::ERR_EMPTY_RESPONSE core.js:

我正在尝试使用Angular 4、nodejs、mailgun js和mailgun在注册流上实现一个简单的电子邮件确认。问题在于邮枪发送:

mailgun.messages().send(data, function(error, body) {
        console.log(body);
    });
正在超时,前端出现以下错误:

POST http://localhost:3000/users/sendMail net::ERR_EMPTY_RESPONSE
core.js:1448 ERROR 
HttpErrorResponse {headers: HttpHeaders, status: 0, statusText: "Unknown Error", url: null, ok: false, …}
error
:
ProgressEvent {isTrusted: true, lengthComputable: false, loaded: 0, total: 0, type: "error", …}
headers
:
HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, headers: Map(0)}
message
:
"Http failure response for (unknown url): 0 Unknown Error"
name
:
"HttpErrorResponse"
ok
:
false
status
:
0
statusText
:
"Unknown Error"
url
:
null
__proto__
:
HttpResponseBase
后端show now出现错误,但返回值(正文)未定义,电子邮件未发送。这是我完整的后端sendMail模块:

const api_key = '<key-f40360259dea7c667ca06d4aee956421>';
const DOMAIN = '<sandbox836cdf3cfe9c467b916fe5bb0d73e7e7.mailgun.org>';
const mailgun = require('mailgun-js')({ apiKey: api_key, domain: DOMAIN });
// ---------------- sendMail variables -----

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

    console.log("Email message data: " + JSON.stringify(req.body));

    const data = {
        from: 'xxxxdev@gmail.com',
        to: [req.body.email, 'xxxxxxx@gmail.com'],
        name: req.body.firstName,
        code: req.body.workshopCode,
        subject: req.body.workshopTitle,
        text: req.body.messageBody
    };

    mailgun.messages().send(data, function(error, body) {
        console.log(body);
    });
});
 sendEmailConfirmation(message) {
     const headers = new HttpHeaders();
     headers.append('Content-Type', 'application/x-www-form-urlencoded');

     this.http.post('http://localhost:3000/users/sendMail', message).subscribe((data) => {
          console.log('Mail return data: ' + data);   >>>THIS LINE IS NEVER EXECUTED<<<<<<
              },
        );
  }
现在我在后端发现了一个禁止的错误:

(node:10780) UnhandledPromiseRejectionWarning: Error: Forbidden
    at IncomingMessage.res.on (C:\connect2Server\node_modules\mailgun-js\lib\request.js:301:17)
    at IncomingMessage.emit (events.js:165:20)
    at endReadableNT (_stream_readable.js:1101:12)
    at process._tickCallback (internal/process/next_tick.js:152:19)
(node:10780) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a ca
tch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)

问题已解决…由mailgun凭据中的键入错误引起。复制到的“”括号…提示是禁止的错误。

您是否尝试将错误记录到mailgun API调用的回调中?您得到
ERR\u EMPTY\u响应的原因是,在发送邮件后,您从未使用类似于
res.sendStatus(200)
的命令结束请求,如果成功,或者使用
res.sendStatus(500)
的命令结束请求。@Svenskunganka我注意到了这一点,并使用(请参见编辑)res.send(“…”)。我得到以下信息:…(节点:10780)未处理PromisejectionWarning:错误:禁止
(node:10780) UnhandledPromiseRejectionWarning: Error: Forbidden
    at IncomingMessage.res.on (C:\connect2Server\node_modules\mailgun-js\lib\request.js:301:17)
    at IncomingMessage.emit (events.js:165:20)
    at endReadableNT (_stream_readable.js:1101:12)
    at process._tickCallback (internal/process/next_tick.js:152:19)
(node:10780) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a ca
tch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)