Skip to content

Commit fcfde28

Browse files
committed
send emails
1 parent 598ba5e commit fcfde28

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

server/services/Mailer.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Mailer extends helper.Mail {
66
constructor({ subject, recipients }, content) {
77
super();
88

9+
this.sgApi = sendgrid(keys.sendGridKey);
910
this.from_email = new helper.Email('no-reply@emaily.com');
1011
this.subject = subject;
1112
this.body = new helper.Content('text/html', content);
@@ -29,6 +30,26 @@ class Mailer extends helper.Mail {
2930
trackingSettings.setClickTracking(clickTracking);
3031
this.addTrackingSettings(trackingSettings);
3132
}
33+
34+
addRecipients() {
35+
const personalize = new helper.Personalization();
36+
37+
this.recipients.forEach(recipient => {
38+
personalize.addTo(recipient);
39+
});
40+
this.addPersonalization(personalize);
41+
}
42+
43+
async send() {
44+
const request = this.sgApi.emptyRequest({
45+
method: 'POST',
46+
path: '/v3/mail/send',
47+
body: this.toJSON()
48+
});
49+
50+
const response = this.sgApi.API(request);
51+
return response;
52+
}
3253
}
3354

3455
module.exports = Mailer;

0 commit comments

Comments
 (0)