From 292de0c7581889a9ed30db331d462478f5a0b867 Mon Sep 17 00:00:00 2001 From: Robert Marzec Date: Thu, 30 Sep 2021 20:03:03 -0400 Subject: [PATCH] got mailgun to email out verfication emails, minus having the actual important content alongside it --- Dockerfile | 3 ++- package.json | 1 + server/db/model/User.js | 18 ++++++++++++++-- server/interactors/email.js | 41 ++++++++++++++++++++++++++++++++++++- 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 85e6a888..f4588e00 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,13 @@ FROM node:12 -LABEL maintainer="MHacks Team " +LABEL maintainer="MHacks Team " ARG NODE_ENV ENV NODE_ENV $NODE_ENV WORKDIR /usr/src/app RUN npm install -g nodemon +RUN npm install mailgun-js ADD yarn.lock . ADD package.json . diff --git a/package.json b/package.json index 3fb965d8..63f68ee9 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "jsonwebtoken": "^8.5.1", "lodash": "^4.17.19", "mailchimp-api-v3": "^1.13.1", + "mailgun-js": "^0.22.0", "mailgun.js": "^3.5.9", "mandrill-api": "^1.0.45", "mime": "^2.4.4", diff --git a/server/db/model/User.js b/server/db/model/User.js index efe28d79..27714ca0 100644 --- a/server/db/model/User.js +++ b/server/db/model/User.js @@ -530,7 +530,7 @@ schema.methods.changePassword = function(password) { }; schema.methods.sendVerificationEmail = function() { - if (config.development) { + if (!config.development) { console.log( emailResponses.VERIFICATION_URL_CONSOLE, config.host + @@ -538,7 +538,19 @@ schema.methods.sendVerificationEmail = function() { this.generateEmailVerificationToken() ); } else { + var verification_content = 'Hi '; + verification_content += this.full_name + ? this.full_name.split(' ')[0] + : 'Hacker'; + verification_content += '! Thanks for signing up for MHacks! Please click the following link to verifiy your email { - console.error('MANDRILL', error); + console.error('MAILGUN VERIFICATION EMAIL ERROR: ', error); return false; }); } diff --git a/server/interactors/email.js b/server/interactors/email.js index d7cce85c..ef284435 100644 --- a/server/interactors/email.js +++ b/server/interactors/email.js @@ -77,10 +77,46 @@ function sendEmailTemplate( from_email, from_name ) { + console.log('@@@@@@@@@@@@@@@'); + return new Promise((resolve, reject) => { + console.log('111111111111'); + + var DOMAIN = 'mhacks.org'; + var api_key = 'key-3c4f7813f2541f7b7ac2774aa91a6b1c'; + var mailgun = require('mailgun-js')({ apiKey: api_key, domain: DOMAIN }); + + console.log('2222222222222'); + + console.log(template_content); + + var data = { + from: from_email, + to: to_email, + cc: 'hackathon@mhacks.org', + subject: subject, + html: template_content, + }; + + console.log('33333333333333'); + + mailgun.messages().send(data, function (error, body) { + console.log(body); + if(error) + { + reject(error); + } + else + { + resolve(body); + } + }); + + + /* mg.messages.create('mhacks.org', { from: from_email, - to: [to_email], + to: to_email, subject: subject, text: template_content, }) @@ -93,6 +129,9 @@ function sendEmailTemplate( reject(err); }); // logs any error + mg.messages.sendTemplate + */ + /* if (!config.mandrill_token) { reject(Errors.MISSING_CONFIG);