提问人:ICTDEV 提问时间:11/8/2023 更新时间:11/15/2023 访问量:2520
Nodemailer - 弃用警告:“punycode”模块已弃用
Nodemailer - DeprecationWarning: The `punycode` module is deprecated
问:
我需要创建一个脚本,每天使用 gmail 帐户发送一次邮件。我使用了nodemailer,我有这个简单的测试代码
const fs = require('fs');
const path = require('path');
const nodemailer = require('nodemailer');
const transport = nodemailer.createTransport({
host: 'smtp.gmail.com',
//secure: true,
//port: 465,
auth: {
user: '[email protected]',
pass: 'mypassword'
}
})
let mailOptions = {
from: '[email protected]', // sender address
to: '[email protected]', // list of receivers
subject: 'Test email', // Subject line
text: 'this is some text', //, // plaintext body
html: '<b>Hello world </b>' // You can choose to send an HTML body instead
}
transport.sendMail(mailOptions, (error, info) => {
if( error ) {
return false;
} else {
console.log('Message sent: ' + info.response);
return true;
};
});
我注意到,当我尝试使用运行时,我总是会遇到此错误node index.js
(node:20496) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
代码是否有任何问题,或者是 nodemailer 错误?还有其他选择吗?
答:
1赞
David
11/15/2023
#1
我只是遇到了同样的问题。您需要将节点版本降级到 20.9.0。
评论
3赞
ICTDEV
11/15/2023
降级是一个痛苦的过程,最好的解决方案是等到 nodemailer 更新源代码
评论
mail-composer