forked from CodeChefVIT/webinar-flow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.js
83 lines (70 loc) · 2.14 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
var ical = require('ical-generator')
var nodemailer = require('nodemailer')
var fs=require('fs')
var cal=ical()
var path=undefined
// replace the username and password by sender's email and password where ever mentioned as process.env.username and process.env.password
const options={
pool:true,
host:'smtp.gmail.com',
port:587,
secure:false,
auth:{
user: process.env.username,
pass:process.env.password
}
}
const mail=(mailTo,subject,desc)=>new Promise((resolve,reject)=>{
var transporter=nodemailer.createTransport(options,null)
var mailOptions = {
from: process.env.username,
to: mailTo,
subject,
text: desc ,
attachments:[{
filename:'invite.ics',
path:path
}]
}
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
reject(error)
} else {
console.log('Email sent: ' + info.response);
resolve(info)
}
})
})
const mailMany=(send)=>{
if(send.verified==false)
{
send.webinarData.description=send.webinarData.description + ". Verify your email using the following link " + send.verificationLink
}
var eventObj = {
start : send.webinarData.startTime,
end : send.webinarData.endTime,
title : send.webinarData.name,
description : send.webinarData.description,
id : 'wdcwe76234e127eugb', //Some unique identifier
organiser : {name : 'CODECHEF-VIT', email:process.env.username}
}
cal.createEvent({
start: eventObj.start,
end: eventObj.end,
summary: eventObj.title,
uid: eventObj.id, // Some unique identifier
sequence: 0,
description: eventObj.description,
organizer: {
name: eventObj.organiser.name,
email: eventObj.organiser.email
},
method: 'request'
});
//uploads folder has already been made to save invite.ics files to send invites
path = __dirname + '/uploads/'+ 'invite' + '.ics';
cal.saveSync(path);
mail(send.email,send.webinarData.name,send.webinarData.description)
}
module.exports=mailMany