-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail.js
51 lines (40 loc) · 1.33 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
/*
* Usage: .isService() - "iv-user" header is set to "service" AND "iv-groups" contains "service"
*/
exports.mail = function(request, response){
var checkaccess = require('./accessControl.js');
// check headers
var retcode = checkaccess.isService(request, response);
console.log("/mail isService:" + retcode);
// TESTING TESTING TESTING ignore header for now
// retcode = true;
if (retcode == true ) {
// process mail
const email = request.query.email;
const subject = request.query.subject;
const body = request.query.body;
console.log(email);
console.log(subject);
console.log(body);
response.send("/mail email sent");
var helper = require("sendgrid").mail;
to_email = new helper.Email(email);
content = new helper.Content("text/plain", body);
from_email = new helper.Email("test@example.com");
mail = new helper.Mail(from_email, subject, to_email, content);
var sg = require("sendgrid")(process.env.SENDGRID_API_KEY);
var request = sg.emptyRequest({
method: "POST",
path: "/v3/mail/send",
body: mail.toJSON()
});
sg.API(request, function(error, response) {
console.log(response.statusCode);
console.log(response.body);
console.log(response.headers);
});
return 0;
}
response.send("/mail email not sent");
return -1;
};