首先需要安装一下nodemailer

#nmp nodemailer install --save

然后就参照官方文档的例程改写一下就行了,代码如下:

  1. 'use strict';
  2. const nodemailer = require('nodemailer');
  3.  
  4. // Generate test SMTP service account from ethereal.email
  5. // Only needed if you don't have a real mail account for testing
  6. nodemailer.createTestAccount((err, account) => {
  7. // create reusable transporter object using the default SMTP transport
  8. let transporter = nodemailer.createTransport({
  9. host: 'smtp.163.com',
  10. port: 465,
  11. secure: true, // true for 465, false for other ports
  12. auth: {
  13. user: 'abc@163.com', // generated ethereal user
  14. pass: 'PASSWORD' // generated ethereal password
  15. }
  16. });
  17.  
  18. // setup email data with unicode symbols
  19. let mailOptions = {
  20. from: 'abc@163.com', // sender address
  21. to: 'abc@163.com,def@163.com', // list of receivers
  22. subject: '标题:这是一封来自Nodejs发送的邮件', // Subject line
  23. text: '你好吗?', // plain text body
  24. html: '<b>北京欢迎你</b>' // html body
  25. };
  26.  
  27. // send mail with defined transport object
  28. transporter.sendMail(mailOptions, (error, info) => {
  29. if (error) {
  30. return console.log(error);
  31. }
  32. console.log('Message sent: %s', info.messageId);
  33. // Preview only available when sending through an Ethereal account
  34. console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
  35.  
  36. // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
  37. // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
  38. });
  39. });

赘述一下:nodemailer的官网在 https://nodemailer.com/about/ ,一般看原文比网文靠谱。

使用Nodejs的Nodemailer通过163信箱发送邮件例程的更多相关文章

  1. app里使用163邮箱发送邮件,被163认为是垃圾邮件的坑爹经历!_ !

    最近有个项目,要发邮件给用户设定的邮箱报警,然后就用了163邮箱,代码是网上借来的^^,如下: package com.smartdoorbell.util; import android.os.As ...

  2. phpmailer使用163邮件发送邮件例子

    注意:如果你的服务器安装了卖咖啡并且开户病毒最大防护功能我们需要关闭一个邮件防护哦,否则你的邮件发不出去给被这款杀毒给拦截哦. 1. 使用gmail发送的脚本 代码如下 复制代码 include(&q ...

  3. java调用163邮箱发送邮件

    1:注册一个163邮箱,http://mail.163.com 调用发送邮件代码,查询smtp.163.com,作为发送邮件的服务器ip,类似的邮箱服务器应该也可以. MailSenderInfo m ...

  4. dedecms织梦自定义表单发送到邮箱-用163邮箱发送邮件

    https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&tn=monline_3_dg&wd=dedecms 邮箱&oq=d ...

  5. python使用随机的163账号发送邮件

    import linecache import smtplib import time import linecache import random #算出txt的行数,163账号_2.txt中,每一 ...

  6. CentOS7像外部163邮箱发送邮件

    我们在运维过程中,为了随时了解服务器的工作状态,出现问题随时提醒,像个人邮箱发送邮件是必须的,但是刚刚安装好的系统是无法发送邮件的.需要们进行一些配置和程序的安装,我安装完系统后,自带mail12.5 ...

  7. java连接163邮箱发送邮件

    一:jar包:下载链接:链接: http://pan.baidu.com/s/1dDhIDLv 密码: ibg5二:代码 1-------------------------------------- ...

  8. Linux下用mail 命令给163邮箱发送邮件!

    linux上的邮件客户端比较多,找一个平时用的比较多mail命令来试试!! 环境 :centos7: 注意 : 服务器必须得有外网才行,qq邮箱作为在linux上的发送端邮箱,经过测试 163 和qq ...

  9. MUTT+MSMTP利用163服务器发送邮件

    监控系统发送告警邮件,我们自己搭建邮件服务器,成本较高,所以可以使用163等第三方MTA帮助我们发送.MUTT+MSMTP是一个很好的选择,具体实现如下: tar -xvf msmtp-1.6.5.t ...

随机推荐

  1. here with you

    Here With You - Asher Book To all my friends对我所有好友来讲The night is young夜未央The music's loud乐未殇They pla ...

  2. Codeforces 992 E. Nastya and King-Shamans

    \(>Codeforces\space992 E. Nastya and King-Shamans<\) 题目大意 : 给你一个长度为 \(n\) 的序列,有 \(q\) 次操作,每一次操 ...

  3. JZYZOJ1237 教授的测试 dfs

    http://172.20.6.3/Problem_Show.asp?id=1237   锻炼搜索的代码能力,不错的题. 开始对dfs到底向下传递什么搞不清楚,需要想一下,noip难度的题还有这种情况 ...

  4. CXF和Axis2的区别

    1.CXF支持 WS-Addressing,WS-Policy, WS-RM, WS-Security和WS-I Basic Profile.Axis2不支持WS-Policy,但是承诺在下面的版本支 ...

  5. PHP 基础函数(一)数组的键名和值

    array_values($arr);  获取数组的值,键名消失,原数组不变,返回转变后的数组:

  6. activemq 消息传送测试

    activemq 5.10.0,topic   messagelength字符 20000011     发送时间 接收时间 传送时间 毫秒 1 1443067284128 1443067288325 ...

  7. hssworkbook 用法案例

    public ActionResult excelPrint() { HSSFWorkbook workbook = new HSSFWorkbook();// 创建一个Excel文件 HSSFShe ...

  8. 发现一个可以搜索常用rpm包的地址(http://www.rpmfind.net/)

    http://www.rpmfind.net/ 虽然资源不多,但也够用.

  9. 用Javascript轻松制作一套简单的抽奖系统

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN"> <html> <head ...

  10. Java常量字符串String理解 String理解

    以前关于String的理解仅限于三点:1.String 是final类,不可继承2.String 类比较字符串相等时时不能用“ == ”,只能用  "equals" 3.Strin ...