Last active
October 6, 2017 17:24
-
-
Save RobsonX4/1284e8abb666295a6ed3f0c43f4f0ff1 to your computer and use it in GitHub Desktop.
Code Crumbs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //npm i nodemailer --save | |
| var nodemailer = require('nodemailer'); | |
| function sendEmail(subject, emailBody, email){ | |
| let myEmail = 'myEmailAddress'; | |
| let transporter = nodemailer.createTransport({ | |
| service: 'Hotmail', //Gmail, Hotmail | |
| auth: { | |
| user: myEmail, | |
| pass: 'suaSenha' | |
| } | |
| }); | |
| let mailOptions = { | |
| from: myEmail, | |
| to: email, // list of receivers | |
| subject: subject, | |
| text: emailBody //Corpo do email,html `` | |
| }; | |
| transporter.sendMail(mailOptions, function(error, info){ | |
| if(error){ | |
| console.log(error); | |
| return; | |
| } | |
| console.log('Email sent: ' + info.response); | |
| }); | |
| } | |
| module.exports.sendEmail = sendEmail; | |
| //Exemplo de uso | |
| var Mailer = require('./mailer'); | |
| Mailer.sendEmail('subject', 'email body', 'email'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment