Nodejs 发送邮件 nodemailer

我会带着你远行 2022-09-14 02:31 274阅读 0赞

代码

  1. var nodemailer = require("nodemailer")
  2. var transport = nodemailer.createTransport({
  3. host: "smtp.exmail.qq.com", //主机
  4. secureConnection: true, //使用SSL
  5. port: 465, // STMP端口号。邮箱设置页面里有显示
  6. auth:{
  7. user: "jerryjin@qq.com", //账号
  8. pass: "KQNQGTZefCvRgbCZ" //客户端密码(与登录密码不同,要到邮箱设置页面生成)
  9. }
  10. })
  11. function sendMail(to, cc, bcc, subject, content, attach){
  12. var mailOptions = {
  13. from: "jinxin@bctech8.com", // 发件人
  14. to: to, //收件人,多个收件人用,号隔开
  15. cc: cc, //抄送
  16. bcc bcc, //秘送
  17. subject: subject, //标题
  18. text: content, //纯文本
  19. //html: " <b>你好啊!</b>",
  20. attachments: [
  21. {
  22. filename: "检测报告",
  23. path: attach //文件路径
  24. },
  25. {
  26. filename: "fileName", //文件名
  27. content: "texttexttext" //文件内容,自己写
  28. }
  29. ]
  30. }
  31. transport.sendMail(mailOptions, function(err, response) {
  32. if(err)console.log(err)
  33. else console.log(response)
  34. });
  35. }
  36. module.exports = {
  37. sendMail
  38. }

参考资料

https://nodemailer.com/message

发表评论

表情:
评论列表 (有 0 条评论,274人围观)

还没有评论,来说两句吧...

相关阅读