Created
December 18, 2017 16:50
-
-
Save diegogurgel/490bdea5a5f16bae1f0372a0a26008fc to your computer and use it in GitHub Desktop.
mail.js
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
'use strict'; | |
const nodemailer = require('nodemailer'); | |
const {smtp} = require('./config.json'); | |
const smtpTransport = require('nodemailer-smtp-transport'); | |
// 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(smtpTransport({ | |
host: smtp.host, | |
port: smtp.port, | |
secureConnection: true, | |
auth: { | |
user: smtp.user, | |
pass: smtp.password, | |
} | |
})); | |
// setup email data with unicode symbols | |
let mailOptions = { | |
from: '<[email protected]>', // sender address | |
to: '[email protected]', // list of receivers | |
subject: 'Event confirmation', // Subject line | |
html: '<script type="application/ld+json">{"@context": "http://schema.org","@type": "EventReservation","reservationNumber": "A12D4F","reservationStatus": "http://schema.org/Confirmed","underName": {"@type": "Person","name": "John Smith"},"reservationFor": {"@type": "Event","name": "Curso Estratégias Empresariais para MPE","startDate": "2018-02-01T19:30:00-08:00","location": {"@type": "Place","name": "Sebrae Uberaba","address": {"@type": "PostalAddress","streetAddress": "Av. Leopoldino de Oliveira, 3439","addressLocality": "Uberaba","addressRegion": "MG","postalCode": "30010000","addressCountry": "BR"}}},"ticketToken": "qrCode:A12D4F","ticketNumber": "A12D4F"}</script>' // 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: <[email protected]> | |
// Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou... | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment