nodejs & nodemailer
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的更多相关文章
- nodejs nodemailer中间件
var stransporter = nodemailer.createTransport({ host:smtp-163.com', //适合163 secureConnection: true, ...
- nodejs nodemailer 使用
index.js const nodemailer=require("nodemailer") let sendEmail=function () { var transporte ...
- 54.nodejs nodemailer不兼容
转自:https://blog.csdn.net/q36835109/article/details/53067917 注:由于本人使用最新版本的nodemailer不兼容,所以目前使用的是0.7.1 ...
- Nodejs之发送邮件nodemailer
nodejs邮件模块nodemailer的使用说明 1.介绍 nodemailer是node的一个发送邮件的组件,其功能相当强大,普通邮件,传送附件,邮件加密等等都能实现,而且操作也十分方便. nod ...
- 使用Nodejs的Nodemailer通过163信箱发送邮件例程
首先需要安装一下nodemailer #nmp nodemailer install --save 然后就参照官方文档的例程改写一下就行了,代码如下: 'use strict'; const node ...
- nodeJs的nodemailer发邮件报错hostname/IP doesn't match certificate's altnames怎么解决?
今天在开发过程中碰到一个问题,即使用node发送邮件时报错hostname/IP doesn't match certificate's altnames,在网上查了解决办法有两个, 加rejectU ...
- 使用nodemailer发送邮件
今天闲来无事,一时兴起看了下如果使用javascript来发送邮件.经过调研发现,nodeJs可以实现这个功能. 具体的步骤如下: 1.安装依赖 npm install nodemailer -g ( ...
- nodemailer中的几个坑
nodemailer是什么 nodemailer是一个nodejs的邮件服务模块 如何用nodemailer发邮件 1.先安装nodemailer npm i --save nodemailer 2. ...
- NodeJs之邮件(email)发送
NodeJs之邮件(email)发送 一,介绍与需求 1.1,介绍 1,Nodemailer简介 Nodemailer是一个简单易用的Node.js邮件发送插件 github地址 Nodemailer ...
随机推荐
- CSS篇章
页面的组成:页面=数据(后台技术jsp|asp|.net|php|python)+Html(显示)+CSS(样式)+js(动效) CSS:层叠样式表 特点:①CSS和HTML分离 ...
- Java技术的特点
Java技术是一套完整的IT行业解决方案,其中包含了很多技术.最初是从解决家电设备联网通讯的方案发展起来的,其特点适用于Internet,于是在Internet广泛应用的环境下,迅速发展成为一种计算机 ...
- HDU 1796 容斥原理
How many integers can you find Time Limit: 12000/5000 MS (Java/Others) Memory Limit: 65536/32768 ...
- UILabel 的高度根据文字内容调整
1.UILabel 对文字的自适应有两种方法. 1)将label的numberOfLines设为0;并添加自适应方法[titleLabel sizeToFit],但是这种方法并不理想. 2)根据文字的 ...
- poj2369 Permutations ——置换群
link:http://poj.org/problem?id=2369 置换群,最简单的那种. 找所有数字循环节的最小公倍数. /* ID: zypz4571 LANG: C++ TASK: perm ...
- postfix启动脚本
使用该脚本是一定要注意postfix安装路径 #!/bin/bash # # postfix Postfix Mail Transger Agent # # chkconfig: # descript ...
- 怎么实时查看mysql当前连接数
如何实时查看mysql当前连接数? 如何实时查看mysql当前连接数? .查看当前所有连接的详细资料: ./mysqladmin -uadmin -p -h10. processlist .只查看当前 ...
- [hdu 4307]Matrix
真是一道很好的题目喵~ 一看题面真是无语了……很直接.很暴力.很恶心.说实话,除了 straight forward 我脑子里就没想过别的 上网看了一下居然是最小割,脑子里面一下子就清醒了,N< ...
- knockout 学习实例2 text
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Action、Action<T>、Func<T> 匿名函数的写法
void ht_HLB_Set(Dictionary<int, int> dic) { //匿名函数 Action<int> fun = (int jhShare_Iid) = ...