I'm trying to send an email verification via Sendgrid to users who have signed up for the first. Following the v3_mail example found here, I've created the following implementation:
const querystring = require('querystring');
const helper = require('sendgrid').mail;
const https = require('https');
const url = "http://<mywebsite.com>/users/reset/passwordLoggedOut?";
let sg = require('sendgrid')(process.env.SENDGRID_API_KEY);
const emails = {};
function sendMail(mail){
const 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);
console.log(error);
});
}
emails.sendActivationEmail = function(user){
let qso = {username: user.username, activationCode: user.activationCode};
let qs = querystring.stringify(qso);
let from = new helper.Email('Thomas.Talhelm@chicagobooth.edu');
let to = new helper.Email(user.username);
let subject = 'Welcome to Psych Study \'16';
let content = new helper.Content('text/html', "<p> Thanks for signing up " +
"for our psych study, please <a href=\"http://<mywebsite.com>/users/validate/account?" +
qs + "\">confirm your email</a></p>");
let mail = new helper.Mail(from, subject, to, content);
sendMail(mail);
console.log('Mail Sent!');
}
module.exports = emails;
Anytime I signup a user, these functions are eventually called without error, although I receive a status code of 202 (response received, email is queued for delivery), and the email never gets sent. The problem is somewhat similar to this one, but my activity log is blank even though I've entered the SendGrid API properly by an environment variable which is well-defined. I've tried re-creating my API key, used full permissions on the key, and have not found an explanation for this behavior from the API.