From 96c524a90c75422da508f605bb6d5a1a2b99c653 Mon Sep 17 00:00:00 2001 From: vjrj Date: Tue, 23 Jan 2018 20:29:36 +0100 Subject: [PATCH] Only send emails to users with emails --- .../api/Users/server/send-welcome-email.js | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/imports/api/Users/server/send-welcome-email.js b/imports/api/Users/server/send-welcome-email.js index c9eac03..10748dd 100644 --- a/imports/api/Users/server/send-welcome-email.js +++ b/imports/api/Users/server/send-welcome-email.js @@ -1,3 +1,4 @@ +import { Meteor } from 'meteor/meteor'; import i18n from 'i18next'; import sendEmail from '../../../modules/server/send-email'; import getOAuthProfile from '../../../modules/get-oauth-profile'; @@ -9,20 +10,20 @@ export default (options, user, lang) => { const applicationName = i18n.t('AppName'); const firstName = OAuthProfile ? OAuthProfile.name.first : options.profile.name.first; const emailAddress = OAuthProfile ? OAuthProfile.email : options.email; - - return sendEmail({ - to: emailAddress, - from: `${applicationName} `, - subject: `[${applicationName}] Welcome, ${firstName}!`, - lang, - template: 'welcome', - templateVars: { - applicationName, - firstName, - welcomeUrl: Meteor.absoluteUrl('subscriptions') // e.g., returns http://localhost:3000/documents - } - }) - .catch((error) => { + if (emailAddress) { + sendEmail({ + to: emailAddress, + from: `${applicationName} `, + subject: `[${applicationName}] Welcome, ${firstName}!`, + lang, + template: 'welcome', + templateVars: { + applicationName, + firstName, + welcomeUrl: Meteor.absoluteUrl('subscriptions') // e.g., returns http://localhost:3000/documents + } + }).catch((error) => { throw new Meteor.Error('500', `${error}`); }); + } };