-
Notifications
You must be signed in to change notification settings - Fork 4
/
SendGridHelper.js
59 lines (55 loc) · 1.97 KB
/
SendGridHelper.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
const sgMail = require('@sendgrid/mail')
require('dotenv').config();
api_key = process.env.SENDGRID_API_KEY;
exports.sendSignUpEmail = async (data) => {
const { email, name } = data;
console.log(api_key);
sgMail.setApiKey(api_key)
const msg = {
to: email,
from: '[email protected]', // Replace with your email address
subject: 'Welcome to Our Box Office',
templateId: 'd-62c8184216d444c99ec8cea55421638d', // Replace with your SendGrid template ID
dynamic_template_data: {
subject: 'Welcome to Box-Office',
name: name,
// Add any other dynamic data you want to include in the email
},
};
await sgMail.send(msg)
.then(() => {
console.log('Signup email sent successfully');
})
.catch((error) => {
console.error('Error sending signup email:', error);
});
}
exports.sendTicketEmail = async (data) => {
const { email, name, movieName, showTime, seatNos, theaterName, qrlink, screenName } = data;
console.log(api_key);
sgMail.setApiKey(api_key)
const msg = {
to: email,
from: '[email protected]', // Replace with your email address
subject: 'Welcome to Our Box Office',
templateId: 'd-1f710be314004ace93e3ca27cfd348aa', // Replace with your SendGrid template ID
dynamic_template_data: {
subject: 'Hey...CinePhile here is your ticket',
name: name,
movieName: movieName,
showTime: showTime,
seatNos: seatNos,
theaterName: theaterName,
qrlink: qrlink,
screenName: screenName
// Add any other dynamic data you want to include in the email
},
};
await sgMail.send(msg)
.then(() => {
console.log('Ticket email sent successfully');
})
.catch((error) => {
console.log('Error sending signup email:', error);
});
}