Node.js use Nodemailer to send message instances

Source: Internet
Author: User
Tags auth

  This article mainly introduced the Node.js use Nodemailer to send the mail the method, the example uses is the QQ mailbox, you may also modify into other mailbox like 163, Gmail and so on, needs the friend to be possible to refer to under

First, install Nodemailer     code as follows: NPM install Nodemailer--save Two, the calling code is as follows: var Nodemailer = require ("Nodemailer");  //Open an SMTP connection pool var smtptransport = Nodemailer.createtransport ("SMTP", {  Host: "Smtp.qq.com",//host   S Ecureconnection:true,//using SSL   port:465,//SMTP Port   Auth: {    User: "xxxxxxxx@qq.com",//account number     Pass: "xxxxxxxx"//Password  }});  //Set message content var mailoptions = {  from: "Fred Foo <xxxxxxxx@qq.com>",//Send address   to: "2838890xx@qq.com , minimixx@126.com ",//Inbox list   Subject:" Hello World ",//title   HTML:" <b>thanks A for visiting!</b> Hello, world! "//HTML content}  //Send mail Smtptransport.sendmail (mailoptions, function (Error, response) {  if (error) {  &NBS P Console.log (Error);  }else{    Console.log ("message Sent:" + response.message);  }   Smtptransport.close (); If it's not working, close the Connection pool});   Three, common error   code is as follows: {[Autherror:invalid login-454Authentication failed, please open SMTP flag first!]   Name: ' Autherror ',   data: ' 454 authentication failed, please open SMTP flag first! ',   stage: ' Auth '} & nbsp Error reason: Account does not set the service solution: QQ mailbox-> set-> account-> Open service: POP3/SMTP service   Code as follows: {[Sendererror:mail from command failed- 501 mail from address must to same as authorization user]   name: ' Sendererror ',   data: ' 501 mail from address Must be same as authorization user ',   stage: ' Mail '} error Reason: The sender account and the authentication account is different

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.