forked from ALPHAVIO/WordNook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.js
34 lines (28 loc) · 798 Bytes
/
mail.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const nodemailer = require('nodemailer')
const mailGun = require('nodemailer-mailgun-transport')
const dotenv = require('dotenv');
dotenv.config();
//api and domain provided by mailgun
const auth = {
auth:{
api_key:process.env.API_KEY,
domain:'sandboxc6297caa1a6a472b8723fdfd8d2b4782.mailgun.org'
}
}
const transporter = nodemailer.createTransport(mailGun(auth))
//to send mail to the recepient
const sendMail = (subject,email,message,cb) =>{
const mailOptions = {
from: email,
to:'[email protected]', //email of verified recipient
subject,
text:message
}
transporter.sendMail(mailOptions, (err,data) =>{
if(err)
cb(err,null)
else
cb(null,data)
})
}
module.exports = sendMail