首页 > 编程语言 >nodejs使用nodemailer发送邮件

nodejs使用nodemailer发送邮件

时间:2023-01-10 18:44:11浏览次数:35  
标签:info nodejs text nodemailer https 邮箱 com 邮件

[nodemailer 官网](https://nodemailer.com/) [nodemailer 使用案例](https://github.com/nodemailer/nodemailer/tree/master/examples) ## 使用案例 [官方案例](https://github.com/nodemailer/nodemailer/blob/master/examples/sendmail.js) email.js ```js /* * @Description: 使用邮箱给对方发送邮件 * @Autor: Bowen * @Date: 2022-03-08 11:14:05 * @LastEditors: Bowen * @LastEditTime: 2022-06-30 09:28:02 */ import nodemailer from "nodemailer"; // 成功开启POP3/SMTP服务,在第三方客户端登录时,登录密码输入以下授权密码 const auth = "XXXXXXXXXXX"; async function sendEmail(options = {}) { // 结构参数 const { to = "[email protected]", // list of receivers subject = "subject", // Subject line text = "text", // plain text body html = "

sendMail success

", // html body attachments = [], // 附件 } = options; // create reusable transporter object using the default SMTP transport let transporter = nodemailer.createTransport({ host: "smtp.163.com", // 163 提供的 host port: 465, // 163 提供的 port secure: true, // true for 465, false for other ports auth: { user: "[email protected]", // generated ethereal user //发送方邮箱 pass: auth, // generated ethereal password //发送方邮箱的授权码,一般去邮箱设置里面找,应该可以找到 }, }); // send mail with defined transport object let info = await transporter.sendMail({ from: "[email protected]", // sender address //发送方邮箱 to, subject, text, html, attachments, }); // console.log("Message sent: %s", info.messageId); // Message sent: <[email protected]> // Preview only available when sending through an Ethereal account // console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info)); // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou... return info; } sendEmail() ```

标签:info,nodejs,text,nodemailer,https,邮箱,com,邮件
From: https://www.cnblogs.com/bitbw/p/17041102.html

相关文章