Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nodemailer sendgrid transport for sending emails (works with tran… #83

Open
wants to merge 1 commit into
base: newDesign
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/services/Export.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ exports.exportUserRegistrations = function (email, requestedDate) {
filename = 'MDG_monthly_report_' + date.subtract('months', 1).format('MM_YYYY') + '.xlsx',
workbook = excelBuilder.createWorkbook('./', filename);

User.findOne({}, null, { sort: { timeCreated: 1 } }).exec(function (err, user) {
oldest = moment(user.timeCreated).startOf('month');
User.find({ timeCreated: { $exists: true } }).sort({ timeCreated: 1 }).limit(1).exec(function (err, user) {
oldest = moment(user[0].timeCreated).startOf('month');

while (date >= oldest) {
months.push({
Expand Down
24 changes: 12 additions & 12 deletions app/services/Mail.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var
directTransport = require('nodemailer-direct-transport'),
sgTransport = require('nodemailer-sendgrid-transport'),
nodemailer = require('nodemailer'),
Configuration = require('../helpers/Configuration'),
fs = require('fs'),
Expand Down Expand Up @@ -28,7 +28,6 @@ function getOptionsForRegistrationEmail (params, fileName, subject) {
from: Configuration.get('mail.from.' + subject),
to: params.user.email,
subject: "Activate your account",
generateTextFromHTML: true,
html: html
};
}
Expand All @@ -48,12 +47,11 @@ function getOptionsForSubscriptionEmail (params, fileName, subject) {
from: Configuration.get('mail.from.' + subject),
to: params.subscription.email,
subject: "MDG schedule export",
generateTextFromHTML: true,
html: html,
attachments: [
{
fileName: 'survey_' + params.subscription._survey._id + '.zip',
contents: new Buffer(params.data, 'binary')
filename: 'survey_' + params.subscription._survey._id + '.zip',
content: new Buffer(params.data, 'binary')
}
]
};
Expand All @@ -72,12 +70,11 @@ function getOptionsForReportEmail (params, fileName, subject) {
from: Configuration.get('mail.from.' + subject),
to: params.email,
subject: "MDG account report",
generateTextFromHTML: true,
html: html,
attachments: [
{
fileName: params.filename,
contents: params.data,
filename: params.filename,
content: params.data,
contentType: 'application/vnd.ms-excel'
}
]
Expand All @@ -98,7 +95,6 @@ function getOptionsForForgotUsernameEmail (params, fileName, subject) {
from: Configuration.get('mail.from.' + subject),
to: params.email,
subject: "Your MDG usernames",
generateTextFromHTML: true,
html: html
};
}
Expand All @@ -117,7 +113,6 @@ function getOptionsForResetPasswordEmail (params, fileName, subject) {
from: Configuration.get('mail.from.' + subject),
to: params.user.email,
subject: "MDG reset password link",
generateTextFromHTML: true,
html: html
};
}
Expand All @@ -138,14 +133,19 @@ function getOptionsForPasswordChangedEmail (params, fileName, subject) {
from: Configuration.get('mail.from.' + subject),
to: params.user.email,
subject: "MDG reset password confirmation",
generateTextFromHTML: true,
html: html
};
}

exports.sendMail = function (params, subject) {
var
mailTransport = nodemailer.createTransport(directTransport({})),
options = {
auth: {
api_user: Configuration.get('mail.transportOptions.user'),
api_key: Configuration.get('mail.transportOptions.key')
}
},
mailTransport = nodemailer.createTransport(sgTransport(options)),
fileName = process.cwd() + Configuration.get('mail.' + subject),
sendMailOptions = {};

Expand Down
4 changes: 4 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ module.exports = {
subscription: '[email protected]',
report: '[email protected]'
},
transportOptions: {
user: '',
key: ''
},
emailsForUsersReport: null,
emailsForUsersReport: []
}
Expand Down
20 changes: 10 additions & 10 deletions configurationSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,21 +291,21 @@ module.exports = {
}
}
},
transport: {
type: String,
title: 'Mail transport',
description: 'Defines mail transport protocol',
defaults: 'Direct'
},
transportOptions: {
title: 'Mail transport Options',
description: 'Defines method for sending e-mails',
children: {
service: {
user: {
type: String,
title: 'Api user',
description: 'Username for SendGrid',
defaults: ''
},
key: {
type: String,
title: 'Service',
description: 'The name of send mail service',
defaults: 'Sendmail'
title: 'Api key',
description: 'Password for SendGrid',
defaults: ''
}
}
},
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"msexcel-builder": "0.0.2",
"nodemailer": "^2.3.2",
"nodemailer-direct-transport": "^3.0.7",
"nodemailer-sendgrid-transport": "^0.2.0",
"passport": "0.1.17",
"passport-http": "~0.2.2",
"passport-local": "0.1.6",
Expand Down