摘要:本篇教程介绍了Node.js教程之使用Node.js的Nodemailer通过163信箱发送邮件例程,希望阅读本篇文章以后大家有所收获,帮助大家对Node.js的理解更加深入。
本篇教程介绍了Node.js教程之使用Node.js的Nodemailer通过163信箱发送邮件例程,希望阅读本篇文章以后大家有所收获,帮助大家对Node.js的理解更加深入。
<
首先需要安装一下nodemailer
#nmp nodemailer install --save
然后就参照官方文档的例程改写一下就行了,代码如下:
‘use strict‘;
const nodemailer = require(‘nodemailer‘);
// Generate test SMTP service account from ethereal.email
// Only needed if you don‘t have a real mail account for testing
nodemailer.createTestAccount((err, account) => {
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: ‘smtp.163.com‘,
port: 465,
secure: true, // true for 465, false for other ports
auth: {
user: ‘abc@163.com‘, // generated ethereal user
pass: ‘PASSWORD‘ // generated ethereal password
}
});
// setup email data with unicode symbols
let mailOptions = {
from: ‘abc@163.com‘, // sender address
to: ‘abc@163.com,def@163.com‘, // list of receivers
subject: ‘标题:这是一封来自Nodejs发送的邮件‘, // Subject line
text: ‘你好吗?‘, // plain text body
html: ‘<b>北京欢迎你</b>‘ // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log(‘Message sent: %s‘, info.messageId);
// Preview only available when sending through an Ethereal account
console.log(‘Preview URL: %s‘, nodemailer.getTestMessageUrl(info));
// Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
});
});
赘述一下:nodemailer的官网在 https://nodemailer.com/about/
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注WEB前端Node.js频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号