Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Commit

Permalink
got mailgun to email out verfication emails, minus having the actual …
Browse files Browse the repository at this point in the history
…important content alongside it
  • Loading branch information
rjmarzec committed Oct 1, 2021
1 parent 2dbedcd commit 292de0c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
FROM node:12

LABEL maintainer="MHacks Team <[email protected]>"
LABEL maintainer="MHacks Team <[email protected]>"

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 .
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 16 additions & 2 deletions server/db/model/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,15 +530,27 @@ schema.methods.changePassword = function(password) {
};

schema.methods.sendVerificationEmail = function() {
if (config.development) {
if (!config.development) {
console.log(
emailResponses.VERIFICATION_URL_CONSOLE,
config.host +
'/v1/auth/verify/' +
this.generateEmailVerificationToken()
);
} else {
var verification_content = '<html><body>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 <a href=';
verification_content += config.host +
'/v1/auth/verify/' +
this.generateEmailVerificationToken();
verification_content += '">here.</a></body></html>';


Email.sendEmailTemplate(
/*
config.confirmation_email_template,
{
confirmation_url:
Expand All @@ -549,12 +561,14 @@ schema.methods.sendVerificationEmail = function() {
? this.full_name.split(' ')[0]
: 'Hacker'
},
*/
this.verification_content,
config.confirmation_email_subject,
this.email,
config.email_from,
config.email_from_name
).catch(error => {
console.error('MANDRILL', error);
console.error('MAILGUN VERIFICATION EMAIL ERROR: ', error);
return false;
});
}
Expand Down
41 changes: 40 additions & 1 deletion server/interactors/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]',
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,
})
Expand All @@ -93,6 +129,9 @@ function sendEmailTemplate(
reject(err);
}); // logs any error
mg.messages.sendTemplate
*/

/*
if (!config.mandrill_token) {
reject(Errors.MISSING_CONFIG);
Expand Down

0 comments on commit 292de0c

Please sign in to comment.