forked from Divineifed1/StrellerMinds-Backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemailService.js
More file actions
42 lines (38 loc) · 1.09 KB
/
emailService.js
File metadata and controls
42 lines (38 loc) · 1.09 KB
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
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
/**
* Send an email using SendGrid
* @param {string} to - Recipient email address
* @param {string} subject - Email subject
* @param {string} text - Plain text content
* @param {string} html - HTML content
*/
async function sendEmail(to, subject, text, html, templateId = null, dynamicTemplateData = {}) {
try {
const msg = {
to,
from: process.env.SENDER_EMAIL,
subject,
text,
html,
templateId,
dynamic_template_data: dynamicTemplateData,
};
const response = await sgMail.send(msg);
console.log('Email sent', response);
} catch (error) {
console.error('Error sending email', error);
}
}
/**
* Track email analytics
* @param {object} eventData - Event data from email service
*/
function trackEmailAnalytics(eventData) {
// Log event or send to analytics service
console.log('Email event:', eventData);
}
module.exports = {
sendEmail,
trackEmailAnalytics,
};