Heroku(Mandrill,SMTP)上的 NodeMailer 请求超时,适用于本地主机
NodeMailer Request timeout on Heroku (Mandrill, SMTP), works on localhost
我在 express / angular 应用程序中使用 nodemailer,并使用 nodemailer
对基本邮件程序进行了一些尝试。
我尝试使用 Hotmail
作为服务,它在本地主机上工作,但在 heroku 上工作
它会不断 return 503
或 Invalid Credentials
即使它有效。
其次,我试图将它与我的 Mandrill 帐户连接起来,代码如下所示:
Angular (ES6):
sendEmail(form) {
var data = {
contactName: form.name,
contactEmail: form.email,
comments: form.comments || null
};
var req = {
method: 'POST',
// url: 'http://localhost:9030/email', <- my express port
url: location.origin + '/email',
// url: 'https://myherokuapp.herokuapp.com/email', <- my heroku app
headers: {
'Content-Type': 'application/json'
},
data: data
};
this.$http(req)
.then((result) => {
console.log('success is...', result);
return result;
})
.catch((error) => {
console.log('error is...', error);
return error;
});
}
快递:
var transport = nodemailer.createTransport("SMTP", {
service: 'Mandrill', // use well known service.
// If you are using @gmail.com address, then you don't
// even have to define the service name
auth: {
user: "xxxxx@gmail.com",
pass: "xxxxxxxxxxxxxxxx"
}
});
console.log('SMTP Configured');
var message = {
// sender info
from: 'Sender: <' + req.body.contactEmail + '>',
// Comma separated list of recipients
to: '"Info:" <info@example.com>',
// Subject of the message
subject: 'Nodemailer is unicode friendly ✔', //
headers: {
'X-Laziness-level': 1000
},
// plaintext body
text: "Interest\n" +
"===========\n" +
"\n" +
"**How** are you?"
};
console.log('Sending Mail');
transport.sendMail(message, function(error) {
if (error) {
console.log('Error occured');
console.log(error.message);
return;
}
console.log('Message sent successfully!');
// if you don't want to use this transport object anymore, uncomment following line
transport.close(); // close the connection pool
});
我真的被卡住了,这感觉像是一项简单的任务,可以在本地主机上工作,但不能在 heroku 上工作。使用 Mandrill SMTP,当我在表单中发送内容时,我在 heroku 上获得了这些日志:
2015-08-24T15:12:58.800676+00:00 app[web.1]: POST /email - - ms - -
2015-08-24T15:13:15.858302+00:00 app[web.1]: { contactName: 'testing',
2015-08-24T15:13:15.858307+00:00 app[web.1]: contactEmail: 'asdf@adsf.com',
2015-08-24T15:13:15.858309+00:00 app[web.1]: comments: 'asdfasdf' }
2015-08-24T15:13:15.858316+00:00 app[web.1]: Email params (name):testing
2015-08-24T15:13:15.858376+00:00 app[web.1]: Email params (email):asdf@adsf.com
2015-08-24T15:13:15.858417+00:00 app[web.1]: Email params (comments):asdfasdf
2015-08-24T15:13:15.858498+00:00 app[web.1]: SMTP Configured
2015-08-24T15:13:15.858537+00:00 app[web.1]: Sending Mail
2015-08-24T15:13:15.889774+00:00 app[web.1]: Message sent successfully!
2015-08-24T15:13:45.845230+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/email" host=secret-river-5414.herokuapp.com request_id=5c1e8378-6971-4253-86e2-a9647fc7e0d4 fwd="14.200.153.28" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0
2015-08-24T15:13:45.857582+00:00 app[web.1]: POST /email - - ms - -
如果有人能解释一下,谢谢!
好的,万一其他人遇到这个问题,
我发现这真的只是我使用的免费托管的问题。
Heroku 使我的请求超时,因为完成操作花费的时间太长,这会关闭邮件程序的连接池。我注意到电子邮件最终通过了,但时间很晚。
只需升级托管计划/扩展测功机并增加工作人员即可纠正此问题
我在 express / angular 应用程序中使用 nodemailer,并使用 nodemailer
对基本邮件程序进行了一些尝试。
我尝试使用 Hotmail
作为服务,它在本地主机上工作,但在 heroku 上工作
它会不断 return 503
或 Invalid Credentials
即使它有效。
其次,我试图将它与我的 Mandrill 帐户连接起来,代码如下所示:
Angular (ES6):
sendEmail(form) {
var data = {
contactName: form.name,
contactEmail: form.email,
comments: form.comments || null
};
var req = {
method: 'POST',
// url: 'http://localhost:9030/email', <- my express port
url: location.origin + '/email',
// url: 'https://myherokuapp.herokuapp.com/email', <- my heroku app
headers: {
'Content-Type': 'application/json'
},
data: data
};
this.$http(req)
.then((result) => {
console.log('success is...', result);
return result;
})
.catch((error) => {
console.log('error is...', error);
return error;
});
}
快递:
var transport = nodemailer.createTransport("SMTP", {
service: 'Mandrill', // use well known service.
// If you are using @gmail.com address, then you don't
// even have to define the service name
auth: {
user: "xxxxx@gmail.com",
pass: "xxxxxxxxxxxxxxxx"
}
});
console.log('SMTP Configured');
var message = {
// sender info
from: 'Sender: <' + req.body.contactEmail + '>',
// Comma separated list of recipients
to: '"Info:" <info@example.com>',
// Subject of the message
subject: 'Nodemailer is unicode friendly ✔', //
headers: {
'X-Laziness-level': 1000
},
// plaintext body
text: "Interest\n" +
"===========\n" +
"\n" +
"**How** are you?"
};
console.log('Sending Mail');
transport.sendMail(message, function(error) {
if (error) {
console.log('Error occured');
console.log(error.message);
return;
}
console.log('Message sent successfully!');
// if you don't want to use this transport object anymore, uncomment following line
transport.close(); // close the connection pool
});
我真的被卡住了,这感觉像是一项简单的任务,可以在本地主机上工作,但不能在 heroku 上工作。使用 Mandrill SMTP,当我在表单中发送内容时,我在 heroku 上获得了这些日志:
2015-08-24T15:12:58.800676+00:00 app[web.1]: POST /email - - ms - -
2015-08-24T15:13:15.858302+00:00 app[web.1]: { contactName: 'testing',
2015-08-24T15:13:15.858307+00:00 app[web.1]: contactEmail: 'asdf@adsf.com',
2015-08-24T15:13:15.858309+00:00 app[web.1]: comments: 'asdfasdf' }
2015-08-24T15:13:15.858316+00:00 app[web.1]: Email params (name):testing
2015-08-24T15:13:15.858376+00:00 app[web.1]: Email params (email):asdf@adsf.com
2015-08-24T15:13:15.858417+00:00 app[web.1]: Email params (comments):asdfasdf
2015-08-24T15:13:15.858498+00:00 app[web.1]: SMTP Configured
2015-08-24T15:13:15.858537+00:00 app[web.1]: Sending Mail
2015-08-24T15:13:15.889774+00:00 app[web.1]: Message sent successfully!
2015-08-24T15:13:45.845230+00:00 heroku[router]: at=error code=H12 desc="Request timeout" method=POST path="/email" host=secret-river-5414.herokuapp.com request_id=5c1e8378-6971-4253-86e2-a9647fc7e0d4 fwd="14.200.153.28" dyno=web.1 connect=1ms service=30000ms status=503 bytes=0
2015-08-24T15:13:45.857582+00:00 app[web.1]: POST /email - - ms - -
如果有人能解释一下,谢谢!
好的,万一其他人遇到这个问题, 我发现这真的只是我使用的免费托管的问题。 Heroku 使我的请求超时,因为完成操作花费的时间太长,这会关闭邮件程序的连接池。我注意到电子邮件最终通过了,但时间很晚。
只需升级托管计划/扩展测功机并增加工作人员即可纠正此问题