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 ...
随机推荐
- QUICK START GUIDE
QUICK START GUIDE This page is a guide aimed at helping anyone set up a cheap radio scanner based on ...
- iOS内部跳转问题
//打开地图 NSString*addressText = @" "; //@"1Infinite Loop, Cupertino, CA 95014&quo ...
- 视频转gif
如何把视频变成GIF https://shop16541393.koudaitong.com/v2/feature/1x6q09fa?openid=ov0dfwb6-DBFqTzvekSNAjT59U ...
- HTML标签之<q> <blockquote>
两个标签都表示“引用”. 不同的是,q标签是行内元素,在内容的开始和结尾处会包有“”,而 blockquote是块级元素,默认带有左右40px的外间距,不带“”. 从语义上讲,前者引用的是小段文字,后 ...
- cocos2dx 3.0 之 lua 创建类 (二)
利用lua 中的table 特性 Base = {x = 0,y = 0} Base.name = "luohai"Base.age = 12Base.sex = "ma ...
- xpcall 安全调用
-- xpall (调用函数f, 错误函数fe[, 参数]) function fun(a,b) -- 这里的参数没什么实际作用,就是展示下用法 return a / bend -- xpc ...
- leetcode52. N-Queens II
Follow up for N-Queens problem. Now, instead outputting board configurations, return the total numbe ...
- linux系统io的copy
#include<stdio.h> #include<sys/types.h> #include<sys/stat.h> #include<fcntl.h&g ...
- java端口扫描(原创)
项目需要扫描占用的端口来判断服务是否启动,通过查资料发现大多数方法都是ServerSocket socket = new ServerSocket(port);代码如下: package com.fr ...
- 转 通过js获取cookie的实例及简单分析
今天review新人写的javascript代码的时候发现了很多的问题.这里以function getCookie(name){}为例. 其中比较典型的一个问题就是如何通过javascript获取co ...