SMTP 服务器 - 无需身份验证/密码即可发送电子邮件?
SMTP server - send emails without auth / password?
我最近收到了向我的代码添加功能的请求。
我的代码的最终结果是同一文件夹中的一堆 .csv
文件。
更新要求我通过电子邮件发送这些文件。
可用和强加的场景是通过 SMTP 来完成。
现在我已经阅读了它,还检查了#nodeMailer npm 包,但它们都需要登录名和密码,但我的经理说我不需要,没有它也可以发送电子邮件。
我有 SMTP 的 IP 地址和发送信件的电子邮件地址。
问题:
- 如何在不实际登录您的邮件帐户的情况下发送电子邮件?
- 如果 nodemailer 不是一个选项,我如何将文件作为内容附加到电子邮件?
- 是否有任何 npm 包,或者您能给我解决方案或链接,我可以继续阅读以实现这种神奇效果吗?
好的,在检查了一些事情和建议后,我得到了以下信息。如果将来有人遇到同样的问题,我会将其作为答案发布。
- 除非得到贵公司的 smtp 授权 check here
,否则您无法在未经身份验证的情况下发送消息
- 如果您有权发送电子邮件,但不知何故收到错误,如果您尝试向自己发送电子邮件,第一个可能的错误是 缺少与 VM 的连接或 apiAddresses 冲突。我已经通过我公司的 VPN 修复了它。
- 修复此问题后,您可能遇到的下一个错误是 sendmail 错误:自签名证书。为了解决这个问题,我找到了答案 here
因此,完成此清单后,发送邮件的最终代码应如下所示:
var transporter = nodemailer.createTransport(smtpTransport({
host: "", // hostname
secure: false, // use SSL
port: , // port for secure SMTP
tls: {
rejectUnauthorized: false
}
}));
var mailOptions = {
from: '', // sender address
to: '', // list of receivers
cc: '', // Comma separated list or an array
subject: 'test upgrde nodemailer subject', // Subject line
html: '<b>Hello world </b>' // html body
};
transporter.sendMail(mailOptions, function(error, info){
if(error){
console.log("/sendmail error");
console.log(error);
res.sendStatus(500);
return;
}else{
console.log("Message sent: " + info.response);
// if you don't want to use this transport object anymore, uncomment following line
socketTimeout: 30 * 1000 // 0.5 min: Time of inactivity until the connection is closed
transporter.close(); // shut down the connection pool, no more messages
res.sendStatus(200);
}
// if you don't want to use this transport object anymore, uncomment following line
transporter.close(); // shut down the connection pool, no more messages
});
我最近收到了向我的代码添加功能的请求。
我的代码的最终结果是同一文件夹中的一堆 .csv
文件。
更新要求我通过电子邮件发送这些文件。
可用和强加的场景是通过 SMTP 来完成。
现在我已经阅读了它,还检查了#nodeMailer npm 包,但它们都需要登录名和密码,但我的经理说我不需要,没有它也可以发送电子邮件。
我有 SMTP 的 IP 地址和发送信件的电子邮件地址。
问题:
- 如何在不实际登录您的邮件帐户的情况下发送电子邮件?
- 如果 nodemailer 不是一个选项,我如何将文件作为内容附加到电子邮件?
- 是否有任何 npm 包,或者您能给我解决方案或链接,我可以继续阅读以实现这种神奇效果吗?
好的,在检查了一些事情和建议后,我得到了以下信息。如果将来有人遇到同样的问题,我会将其作为答案发布。
- 除非得到贵公司的 smtp 授权 check here ,否则您无法在未经身份验证的情况下发送消息
- 如果您有权发送电子邮件,但不知何故收到错误,如果您尝试向自己发送电子邮件,第一个可能的错误是 缺少与 VM 的连接或 apiAddresses 冲突。我已经通过我公司的 VPN 修复了它。
- 修复此问题后,您可能遇到的下一个错误是 sendmail 错误:自签名证书。为了解决这个问题,我找到了答案 here
因此,完成此清单后,发送邮件的最终代码应如下所示:
var transporter = nodemailer.createTransport(smtpTransport({
host: "", // hostname
secure: false, // use SSL
port: , // port for secure SMTP
tls: {
rejectUnauthorized: false
}
}));
var mailOptions = {
from: '', // sender address
to: '', // list of receivers
cc: '', // Comma separated list or an array
subject: 'test upgrde nodemailer subject', // Subject line
html: '<b>Hello world </b>' // html body
};
transporter.sendMail(mailOptions, function(error, info){
if(error){
console.log("/sendmail error");
console.log(error);
res.sendStatus(500);
return;
}else{
console.log("Message sent: " + info.response);
// if you don't want to use this transport object anymore, uncomment following line
socketTimeout: 30 * 1000 // 0.5 min: Time of inactivity until the connection is closed
transporter.close(); // shut down the connection pool, no more messages
res.sendStatus(200);
}
// if you don't want to use this transport object anymore, uncomment following line
transporter.close(); // shut down the connection pool, no more messages
});