nodejs & nodemailer

https://www.npmjs.com/package/nodemailer

上面的連接裏面 有有一個例子; 可以直接拿來用;

  • 安裝依賴,在package.json 中
{
"name":"nodeEmailer",
"version":"0.0.1",
"description":"emailer",
"dependencies":{
"nodemailer": "~0.7.1"
}
}
npm install
  • 新建一個 email.js 文件
var nodemailer = require('nodemailer');

var transporter = nodemailer.createTransport("SMTP",{
service: 'Gmail',
auth: {
user: 'yourEmail@gmail.com',
pass: 'yourPassword'
}
}); var mailOptions = {
from: 'sender address', // sender address
to: 'you want to send email address', // list of receivers
subject: 'Hello ✔', // Subject line
text: 'Hello world ✔', // plaintext body
html: '<b>Hello world ✔</b>' // html body
}; transporter.sendMail(mailOptions, function(error, info){
if(error){
console.log(error);
}else{
console.log('Message sent: ' + info.response);
}
});

上面的例子中 如果出現

[Error: No transport method defined]

可能的原因為

var transporter = nodemailer.createTransport("SMTP",{} 中的 "SMTP"

添加附件

var fs=require('fs');
var img=fs.readFileSync(__dirname+"/1.png"); //讀取文件(圖片)
var attachment=[{
'filename':'1.png', //文件名稱
'contents':img //加載文件 圖片
}];
/**/
var mailOptions = {
from: 'xxxxx@gmail.com', // sender address
to: '4xxxx2@qq.com', // list of receivers
subject: 'Hello ✔', // Subject line
text: 'Hello world ✔', // plaintext body
html: '<b>Hello world ✔</b>' ,// html body
attachments:attachment //添加附件
};

nodejs & nodemailer的更多相关文章

  1. nodejs nodemailer中间件

    var stransporter = nodemailer.createTransport({ host:smtp-163.com', //适合163 secureConnection: true, ...

  2. nodejs nodemailer 使用

    index.js const nodemailer=require("nodemailer") let sendEmail=function () { var transporte ...

  3. 54.nodejs nodemailer不兼容

    转自:https://blog.csdn.net/q36835109/article/details/53067917 注:由于本人使用最新版本的nodemailer不兼容,所以目前使用的是0.7.1 ...

  4. Nodejs之发送邮件nodemailer

    nodejs邮件模块nodemailer的使用说明 1.介绍 nodemailer是node的一个发送邮件的组件,其功能相当强大,普通邮件,传送附件,邮件加密等等都能实现,而且操作也十分方便. nod ...

  5. 使用Nodejs的Nodemailer通过163信箱发送邮件例程

    首先需要安装一下nodemailer #nmp nodemailer install --save 然后就参照官方文档的例程改写一下就行了,代码如下: 'use strict'; const node ...

  6. nodeJs的nodemailer发邮件报错hostname/IP doesn't match certificate's altnames怎么解决?

    今天在开发过程中碰到一个问题,即使用node发送邮件时报错hostname/IP doesn't match certificate's altnames,在网上查了解决办法有两个, 加rejectU ...

  7. 使用nodemailer发送邮件

    今天闲来无事,一时兴起看了下如果使用javascript来发送邮件.经过调研发现,nodeJs可以实现这个功能. 具体的步骤如下: 1.安装依赖 npm install nodemailer -g ( ...

  8. nodemailer中的几个坑

    nodemailer是什么 nodemailer是一个nodejs的邮件服务模块 如何用nodemailer发邮件 1.先安装nodemailer npm i --save nodemailer 2. ...

  9. NodeJs之邮件(email)发送

    NodeJs之邮件(email)发送 一,介绍与需求 1.1,介绍 1,Nodemailer简介 Nodemailer是一个简单易用的Node.js邮件发送插件 github地址 Nodemailer ...

随机推荐

  1. 安装生物信息学软件-Biopython

    其实好多东西装过好多次,然而每次都要翻文档,经常掉进前面掉进过的坑...所以这里重新写一份指南,以防下次再装又忘了(魂淡我并不想再装了啊不要立flag) 1. 安装biopython 1.1 因为bi ...

  2. 学习笔记:HSB、HSL

    转自知乎:http://www.zhihu.com/question/22077462 HSB 为 色相,饱和度,明度, HSL 为 色相,饱和度,亮度, HSV 为色相,饱和度,明度. HSB 和 ...

  3. 用python+selenium将腾讯首页今日话题的内容自动发表到自己cnblog里

    目的:使用pyhton下的unittest单元测试框架并结合selenium的webdriver来实现将腾讯首页的今日话题下的内容自动发表达到自己的cnblog里. 思路:创建QQDailyTopic ...

  4. [转]设置Android手机以使用ARM Streamline进行性能分析(一)

    本博客第一次转载的文章,原文访问不到了,这篇是从google cache里挖出来的,为有需要的同学准备.原文地址     Posted by Fang Bao,(鲍方) 4 Comments 11 J ...

  5. js动态添加onload、onresize、onscroll事件(另类方法)

    js动态添加onload.onresize.onscroll事件(另类方法)   window 的 onload.onresize.onscroll 事件,跟其他的事件不一样,它不能用 attachE ...

  6. HC系列蓝牙模块连接单片机与电脑,传输数据(蓝牙心电测试)

    毕设做无线心电监护.有线的做出来了,AD8232+MCU+LabVIEW上位机.pcb还没时间搞,这个9*7*2.5cm拿来测试能用. 自己做了AD8232的模拟前端,打的板子还没到没法测试. 虽然比 ...

  7. HDU 1796 容斥原理

    How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  8. nginx配置文件重写url不带index.php

    如题: 代码 location / { root /项目目录/; index index.php; if (-f $request_filename/index.php){ rewrite (.*) ...

  9. NOIP2015 跳石头

    一年一度的“跳石头”比赛又要开始了! 这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石.组委会已经选择好了两块岩石作为比赛起点和终点.在起点和终点之间,有 N块岩石(不含起点和终点的岩石). ...

  10. #MySQL for Python(MySQLdb) Note

    #MySQL for Python(MySQLdb) Note #切记不要在python中创建表,只做增删改查即可. #步骤:(0)引用库 -->(1)创建连接 -->(2)创建游标 -- ...