ICT*_*DEV 8 javascript gmail node.js nodemailer
我需要创建一个脚本,使用 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: 'myuser@companyworkspace.com',
pass: 'mypassword'
}
})
let mailOptions = {
from: 'bruno.paolillo@ohspa.it', // sender address
to: 'bruno.paolillo@ohspa.it', // 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;
};
});
Run Code Online (Sandbox Code Playgroud)
我注意到,当我尝试使用运行脚本时,我总是会收到此错误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)
Run Code Online (Sandbox Code Playgroud)
代码有问题还是nodemailer bug?有其他选择吗?
| 归档时间: |
|
| 查看次数: |
16083 次 |
| 最近记录: |