| |
| const transporter = nodemailer.createTransport({ |
| host: "smtp.qq.com",// SMTP 服务器地址 |
| port: 465,// SMTP 端口,对于 SSL 使用 465 |
| secure: true, // 对端口465使用“true”,对所有其他端口使用“false” |
| auth: { |
| user: "发件人邮箱",// 发件人邮箱 |
| pass: "SMTP 授权码",// SMTP 授权码 |
| }, |
| }); |
| |
| // 异步。全局作用域中不允许使用wait,必须使用包装器 |
| async function main() { |
| // 使用定义的传输对象发送邮件 |
| const info = await transporter.sendMail({ |
| from: '发件人地址', // 发件人地址 |
| to: "接收者列表,用逗号隔开", // 接收者列表,用逗号隔开 |
| subject: "主题行 测试 ✔", // 主题行 |
| text: "纯文本正文", // 纯文本正文 |
| html: "<b>html正文</b>", // html正文 |
| attachments: [ |
| // 文本文件附件 |
| { |
| filename: 'demo.txt', |
| path: 'demo.txt', |
| contentType: 'text/plain' |
| }, |
| // 图片附件 |
| { |
| filename: 'image.jpg', |
| path: 'image.jpg', |
| contentType: 'image/jpeg' |
| }, |
| // PDF附件 |
| { |
| filename: 'demo.pdf', |
| path: 'demo.pdf', |
| contentType: 'application/pdf' |
| }, |
| // Word文档附件 |
| { |
| filename: 'demo.docx', |
| path: 'demo.docx', |
| contentType: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' |
| }, |
| { |
| filename: 'demo.zip', |
| path: 'demo.zip', |
| contentType: 'application/zip' |
| }, |
| // 表格文件附件(Excel) |
| { |
| filename: 'demo.xlsx', |
| path: 'demo.xlsx', |
| contentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' |
| }, |
| ] |
| }); |
| |
| console.log("已发送消息: %s", info.messageId); |
| // 已发送消息: <7100cc5a-51c8-60aa-dfb8-531bd086d5b1@qq.com> |
| } |
| |
| main().catch(console.error); |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· .NET Core 中如何实现缓存的预热?
· 三行代码完成国际化适配,妙~啊~
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?