nodejs 發送郵件配置

來源:互聯網
上載者:User

nodejs 發送郵件配置

1,使用nodemailer

 

npm install nodemailer --save-dev

2,建立一個發送郵件的工具包,如email_server.js

 

 

var nodemailer = require('nodemailer');var internals = {};internals.extend = function (o, n) {  for (var p in n) {    if (n.hasOwnProperty(p)) {      o[p] = n[p];    }  };  return o;};var mailConfig = {  service: 'qq',  auth: {    user: '8707***29@qq.com',    pass: '********'  }};var mailOptions = {  from: '870****9@qq.com',  to: 'noahli@**.com',  subject: '測試郵件',  text: '測試郵件內容,請不要回複'};internals.sendEmail = function (_config,_options, attachment) {  mailConfig = internals.extend(mailConfig,_config);  mailOptions = internals.extend(mailOptions,_options);    //執行發送操作  var transporter = nodemailer.createTransport(mailConfig);  transporter.sendMail(mailOptions, function (error, info) {    if (error) {      console.log("郵件發送錯誤:" + error);    } else {      console.log("郵件發送成功:" + info.response);    }  });};exports = module.exports = internals;

3,使用工具發送郵件

 

 

var email_tools = require('./service/email_server');//發送郵箱配置var config = {service: 'qq',auth: {user: '870****9@qq.com',pass: '******'}};//收件匣配置var options = {subject: "測試郵件",text: "我是郵件內容",to: "noahli@****.com",cc:"870***29@qq.com,51****78@qq.com",sender:"imdou8",attachments:[{filename: 'app.js',                        //content: 'hello world!'path:"app.js"}],html:{path:"tpl/index.html"}};email_tools.sendEmail(config, options);


 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.