我想知道是否有人知道如何通过 nodemailer 使用 GoDaddy 托管电子邮件。我的联系表单中有一个电子邮件提交框,它会触发以下脚本:
function sendEmail ( to, subject, body ) {
var transporter = nodemailer.createTransport({
service: 'Godaddy',
host: "relay-hosting.secureserver.net",
port: 465,
secureConnection: true,
auth: {
user: '[email protected]',
pass: 'password'
}
});
var mailOptions = {
from: '[email protected]',
to: to,
subject: subject,
text: body
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
}
我尝试了几种不同的选项,并确保我的端口全部打开,但我在身份验证方面遇到了困难。我不断收到这样的错误:
{ Error: Invalid login: 535 Authentication Failed for [email protected]. User does not have any relays assigned.
at SMTPConnection._formatError (/var/www/node/node_modules/nodemailer/lib/smtp-connection/index.js:577:19)
at SMTPConnection._actionAUTHComplete (/var/www/node/node_modules/nodemailer/lib/smtp-connection/index.js:1306:34)
at SMTPConnection._responseActions.push.str (/var/www/node/node_modules/nodemailer/lib/smtp-connection/index.js:349:26)
at SMTPConnection._processResponse (/var/www/node/node_modules/nodemailer/lib/smtp-connection/index.js:733:20)
at SMTPConnection._onData (/var/www/node/node_modules/nodemailer/lib/smtp-connection/index.js:529:14)
at Socket._socket.on.chunk (/var/www/node/node_modules/nodemailer/lib/smtp-connection/index.js:481:47)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at Socket.Readable.push (_stream_readable.js:134:10)
at TCP.onread (net.js:547:20)
code: 'EAUTH',
response: '535 Authentication Failed for [email protected]. User does not have any relays assigned.',
responseCode: 535,
command: 'AUTH PLAIN' }
任何想法或建议将不胜感激。
这个错误似乎与主机名有关。试试这个:
var transporter2 = nodemailer.createTransport({
service: 'Godaddy',
host: "smtpout.secureserver.net",
secureConnection: true,
port: 465
})
我面临着同样的错误。我将配置更改为以下内容:
var transporter = nodemailer.createTransport({
host: "smtpout.secureserver.net",
secure: true,
secureConnection: false, // TLS requires secureConnection to be false
tls: {
ciphers: "SSLv3",
},
requireTLS: true,
port: 465,
debug: true,
auth: {
user: "[email protected]",
pass: "pass",
},
});
它对我来说就像一种魅力。
万一有人还在寻找这个(就像我最近几天一样!),我发现 GoDaddy 建议的所有服务器信息都是完全错误的。在 cPanel 中找到了答案 - 如果您转到主要部分,然后单击“电子邮件帐户”,则您的帐户右侧应该有一个选项,显示“连接设备”。单击它,它将为您提供所需的正确服务器和端口信息,对我来说最终是这样的:
var transporter = nodemailer.createTransport({
host: "sxb1plzcpnl487525.prod.sxb1.secureserver.net",
secure: true,
secureConnection: true,
port: 465,
auth: {user: "[email protected]", pass: "yourcpanelpassword"},
tls: {rejectUnauthorized: false}
});
我花了很长时间才找到它需要的那个特定的奇怪服务器。希望这可以帮助。对格式表示歉意,这是我在这里发表的第一篇文章,但我想提供帮助,因为我已经花了几天时间在这上面。
如果此代码可以帮助某人,他就为我在 GoDaddy 工作。
“nodemailer”:“^6.9.7”,
.env
AUTH_HOST=smtpout.secureserver.net
[email protected]
AUTH_PASS=Calecogo74330
[email protected]
[email protected]
服务器.js
const sanitizedFormData = {
nom: xss(formData.nom),
email: xss(formData.email),
sujet: xss(formData.sujet),
message: xss(formData.message),
};
const transporter = nodemailer.createTransport({
host: process.env.AUTH_HOST,
port: 465,
secure: true,
auth: {
user: process.env.AUTH_USER,
pass: process.env.AUTH_PASS,
},
debug: true,
});
const mailOptions = {
from: process.env.FROM_EMAIL,
to: process.env.TO_EMAIL,
replyTo: sanitizedFormData.email,
subject: sanitizedFormData.sujet,
html: htmlToSend,
};
// verify connection configuration
transporter.verify(function (error, success) {
if (error) {
console.log(error);
} else {
console.log("Server is ready to take our messages");
}
});
const info = await transporter.sendMail(mailOptions);
console.log("Email sent:", info.response);