diff --git a/packages/rocketchat-channel-settings-mail-messages/client/views/mailMessagesInstructions.js b/packages/rocketchat-channel-settings-mail-messages/client/views/mailMessagesInstructions.js index fcf7349f172..c0c01cd7731 100644 --- a/packages/rocketchat-channel-settings-mail-messages/client/views/mailMessagesInstructions.js +++ b/packages/rocketchat-channel-settings-mail-messages/client/views/mailMessagesInstructions.js @@ -6,7 +6,7 @@ Template.mailMessagesInstructions.helpers({ }, email() { const {emails} = Meteor.user(); - return emails && emails[0].address; + return emails && emails[0] && emails[0].address; }, roomName() { const room = ChatRoom.findOne(Session.get('openedRoom')); @@ -64,12 +64,11 @@ Template.mailMessagesInstructions.events({ const rfcMailPatternWithName = /^(?:.*<)?([a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)(?:>?)$/; const emails = t.$('input[name=to_emails]').val().trim().split(','); const erroredEmails = []; - for (let j = 0, len = emails.length; j < len; j++) { - const email = emails[j]; + emails.forEach((email) => { if (!rfcMailPatternWithName.test(email.trim())) { erroredEmails.push(email.trim()); } - } + }); t.erroredEmails.set(erroredEmails); if (erroredEmails.length > 0) { t.$('.error-invalid-emails').show(); diff --git a/packages/rocketchat-channel-settings-mail-messages/server/methods/mailMessages.js b/packages/rocketchat-channel-settings-mail-messages/server/methods/mailMessages.js index 1a6a6f19334..e5435d0fd43 100644 --- a/packages/rocketchat-channel-settings-mail-messages/server/methods/mailMessages.js +++ b/packages/rocketchat-channel-settings-mail-messages/server/methods/mailMessages.js @@ -33,7 +33,7 @@ Meteor.methods({ if (data.to_users.length > 0) { _.each(data.to_users, (username) => { const user = RocketChat.models.Users.findOneByUsername(username); - if (user && user.emails && user.emails[0].address) { + if (user && user.emails && user.emails[0] && user.emails[0].address) { emails.push(user.emails[0].address); } else { missing.push(username);