-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemailer.js
49 lines (45 loc) · 1.54 KB
/
emailer.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
const { content } = require('googleapis/build/src/apis/content');
const fetch = require('node-fetch');
const credentials = require("./credentials-cal.json")
exports.sendMail = sendMail;
/**
*
* @param {String} email The email to be sent to
* @param {String} content The content of the email
* @param {String} name The name of reciepent optional and defaults to MakerSpace User
* @param {number} milliseconds The number of milliseconds from now to send the email. Optinoal defaults to 0.
*/
function sendMail(email, content, name = "MakerSpace User", milliseconds = 0) {
fetch("https://api.sendgrid.com/v3/mail/send", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${credentials.sendGrid}`,
},
body: JSON.stringify({
from: {
"email": "no-reply@admin.make-it.cc",
"name": "Maker-Space"
},
"personalizations":
[{
"to": [{
"email": email,
"name": name
}],
"subject": "Hello, World!"
}],
"content": [{
"type": "text/plain",
"value": content
}],
reply_to: {
"email": "ajhg@carleton.edu",
"name": "Aaron Heidgerken-Greene"
},
send_at: milliseconds
})
}).then(res => {
console.log({ status: res.status })
})
}