-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact_us.js
48 lines (41 loc) · 1.53 KB
/
contact_us.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
var nodemailer = require('nodemailer');
var smtpTransport = nodemailer.createTransport("SMTP",{
service: "SendGrid",
auth: {
user: process.env.SENDGRID_USERNAME,
pass: process.env.SENDGRID_PASSWORD
}
});
module.exports.handle_request = function (request, response) {
console.log("======== Contact Us Params ========");
console.log(request.body);
console.log("========= End Contact Us ==========");
var subject = request.body.gurevich || '',
text = request.body.himelfeld || '',
from_name = request.body.senders_name || '',
from_email = request.body.senders_email || '',
errors = [];
if (subject === '') errors.push('missing body');
if (text === '') errors.push('missing message text');
if (from_name === '' && from_email === '') errors.push('missing sender name or email');
if (errors.length != 0) {
response.contentType('text/plain');
response.write('Sorry, there was an error sending the message: ' + errors.join(', '));
response.end();
return;
}
var mailOptions = {
from: from_name + " <" + from_email + ">",
to: 'Web Contact-Us Form <[email protected]>',
subject: subject,
text: text
}
smtpTransport.sendMail(mailOptions, function(error, send_res) {
if (error) {
console.log(error);
response.end(500, 'Sorry, there was an error sending the message');
return;
}
response.end('The message has been sent. Thank you!');
});
};