我们开发了几个使用SendGrid发送电子邮件的Bluemix中托管的应用程序。从上周开始,这些应用程序中的每个应用程序都没有在没有任何更改的情况下失败。
事实证明,Bluemix开始超时对SendGrid的请求。我们认为这是SendGrid的问题,所以我们用Amazon SES取代了服务,令我们失望的是,我们开始得到完全相同的错误。
以下是日志的样子:
我们整合了这个简单的NodeJS应用程序,该应用程序向我们提供错误,以查看是否有人看到了什么错误,或者尝试了它并让我们知道这是否真的在另一个Bluemix帐户上失败:
var express = require("express"),
app = express();
var port = process.env.VCAP_APP_PORT || 8080;
var nodemailer = require("nodemailer");
app.use(express.static(__dirname + '/public'));
app.get("/", function (request, response) {
var smtpTransport = nodemailer.createTransport("SMTP",{
host: 'smtp.sendgrid.net',
port: 25,
auth: {
user: "user",
pass: "password"
}
});
var mail = {
from: "noreply@ibm.com",
to: "user@companyXYZ.com",
subject: "Send Email Using Node.js",
text: "Node.js send email test",
html: "<b>Node.js send email test</b>"
};
smtpTransport.sendMail(mail, function(error, resp){
if(error){
console.log(error);
response.write(error);
}
else{
console.log("Message sent: " + resp.message);
response.write("Message sent: " + resp.message);
}
smtpTransport.close();
response.end();
});
});
app.listen(port);
{
"name": "ibm-email-nodejs",
"version": "0.0.1",
"description": "ibm email nodejs",
"main": "app.js",
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "~4.x",
"commander": "^2.6.0",
"http-post": "^0.1.1",
"http-proxy": "^1.8.1",
"nodemailer": "0.7.1"
},
"engines": {
"node": "5.9.1",
"npm": "3.7.3"
}
}
applications:
- path: .
memory: 512M
instances: 1
domain: mybluemix.net
name: ibm-email-nodejs
host: ibm-email-nodejs
disk_quota: 1024M
command: node app.js
答案 0 :(得分:1)
端口587应该可以工作。参考:http://blog.mailgun.com/25-465-587-what-port-should-i-use/
你试过那个吗?请查看代码 https://github.com/sendgrid/smtpapi-nodejs/blob/master/examples/example.js// Use nodemailer to send the email
var settings = {
host: "smtp.sendgrid.net",
port: parseInt(587, 10),
requiresAuth: true,
auth: {
user: process.env.SENDGRID_USERNAME,
pass: process.env.SENDGRID_PASSWORD
}
};