我尝试使用Gmail中的SMTP实现邮件功能。以下代码片段使用emailjs(npm)或gmail-send(npm)正常工作。
在本地,它的工作非常完美,但是当我在Ubuntu VPS上部署它时,它不会工作。我一直在跟踪SMTP。
emailjs:
var email = require("emailjs");
var server = email.server.connect({
user: "from-email@gmail.com",
password:"password",
host: "smtp.gmail.com",
port: 465,
ssl: true
});
server.send({
text: emailbericht,
from: "fromname <from-email@gmail.com>",
to: "toname <to-email@gmail.com>",
subject: "Nieuw contactbericht"
}, function(err, message) { console.log(err); });
gmai-send:
var send = require('gmail-send')({
user: 'from-email@gmail.com',
pass: 'pw',
to: 'my-email@gmail.com',
subject: 'Niew contactbericht',
text: emailbericht
});
send({}, function (err, res) {
console.log('* [example1] send(): err:', err, '; res:', res);
});
现在我真的不知道会出现什么问题。我无法找到解决此问题的任何解决方案。
也许有人在这里知道我是否需要更改我的代码或者应该在我的VPS上修改一些设置。
编辑额外:
平:
PING gmail-smtp-msa.l.google.com(173.194.69.109)56(84)字节 数据。来自ef-in-f109.1e100.net的64字节(173.194.69.109):icmp_seq = 1 ttl = 46 time = 4.34 ms来自ef-in-f109.1e100.net的64字节 (173.194.69.109):icmp_seq = 2 ttl = 46 time = 4.41 ms 64字节来自 ef-in-f109.1e100.net(173.194.69.109):icmp_seq = 3 ttl = 46 time = 4.38 ms 来自ef-in-f109.1e100.net的64字节(173.194.69.109):icmp_seq = 4 ttl = 46 时间= 4.31 msq
异常gmail-send(使用nodemailer):
[example1] send(): err: { Error: Connection timeout at SMTPConnection._formatError (/ijsverenigingpeeloservernode/node_modules/nodemailer/lib/smtp-connection/index.js:557:19) at SMTPConnection._onError (/ijsverenigingpeeloservernode/node_modules/nodemailer/lib/smtp-connection/index.js:530:20) at Timeout._connectionTimeout.setTimeout (/ijsverenigingpeeloservernode/node_modules/nodemailer/lib/smtp-connection/index.js:248:18) at ontimeout (timers.js:488:11) at tryOnTimeout (timers.js:323:5) at Timer.listOnTimeout (timers.js:283:5) code: 'ETIMEDOUT', command: 'CONN' } ; res: undefined
错误消息emailjs:
{[错误:连接到smtp服务器时超时]代码:4,smtp: undefined}