Nodejs uses mailer to send emails

Source: Internet
Author: User

Nodejs uses mailer to send emails

In practical applications, sometimes you need to push messages to you in a timely manner when the server has special information, so that you are prepared and processed. There are a large number of servers in the project, therefore, it is not convenient to Manage Server clusters. When an exception exits on each server, I send an email to my mailbox and restart the Nodejs server.

Not much nonsense, on the instance:

First, install a mail sending module:

npm install mailer

Then introduce the module in the Code:

var email = require(mailer);

Finally, use the module to send an email:

Email. send ({ssl: true, host: smtp.exmail.qq.com, // send smtp.qq.com, receive pop.qq.com domain: [xxx. xxx. xxx. xxx], // you can enter a http://ip.qq.com in your browser/get to: xxx@qq.com, from: xxx@xxx.com, subject: myemail test email, // reply_to: xxx@xxx.com, body: Hello! This is a test of the myemail ., authentication: login, username: xxx@xxx.com, password: xxx, debug: false}, function (err, result) {if (err) {console. log (the err: + err); response. write (JSON. stringify ({prompt message: failed to send, cause of failure: Data Exception}); response. end ();} else {if (result) {console. log (sent successfully); response. write (JSON. stringify ({prompt message: sent successfully}); response. end ();} else {response. write (JSON. stringify ({prompt message: failed to send, cause of failure: Data Exception}); response. end ();}}});

The node. js module is easy to use and may be helpful to you.

 

Related Article

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.