From ee5abf22eb316dce7ef7c20a1eca4ffcd3f25d2d Mon Sep 17 00:00:00 2001 From: Christine Spang Date: Tue, 21 Feb 2017 15:56:49 -0800 Subject: [PATCH] [iso-core] Fix Office365 sending from the mail app Summary: This fixes a regression introduced in D3980 that prevented sending from working on Office365 and generic IMAP accounts. Fixes T7892 Test Plan: manual - we could use unit tests for this but need to set up tests for iso-core first Reviewers: juan, halla, evan Reviewed By: halla, evan Maniphest Tasks: T7892 Differential Revision: https://phab.nylas.com/D4003 --- packages/isomorphic-core/src/auth-helpers.js | 4 ++-- packages/isomorphic-core/src/models/account.js | 17 ++++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/isomorphic-core/src/auth-helpers.js b/packages/isomorphic-core/src/auth-helpers.js index 628a0766e..c1ac47180 100644 --- a/packages/isomorphic-core/src/auth-helpers.js +++ b/packages/isomorphic-core/src/auth-helpers.js @@ -71,9 +71,9 @@ function credentialsForProvider({provider, settings, email}) { const connectionCredentials = { imap_username: email, - imap_password: settings.password, + imap_password: settings.password || settings.imap_password, smtp_username: email, - smtp_password: settings.password, + smtp_password: settings.password || settings.smtp_password, } return {connectionSettings, connectionCredentials} } else if (SUPPORTED_PROVIDERS.has(provider)) { diff --git a/packages/isomorphic-core/src/models/account.js b/packages/isomorphic-core/src/models/account.js index f51e71301..dca860225 100644 --- a/packages/isomorphic-core/src/models/account.js +++ b/packages/isomorphic-core/src/models/account.js @@ -117,21 +117,24 @@ module.exports = (sequelize, Sequelize) => { }, smtpConfig() { + // We always call credentialsForProvider() here because n1Cloud + // sometimes needs to send emails for accounts which did not have their + // full SMTP settings saved to the database. const {connectionSettings, connectionCredentials} = credentialsForProvider({ provider: this.provider, - settings: this.decryptedCredentials(), + settings: Object.assign({}, this.decryptedCredentials(), this.connectionSettings), email: this.emailAddress, }); - const {smtp_host, smtp_port, smtp_username, ssl_required} = connectionSettings; - let config = {} + let config; + const {smtp_host, smtp_port, ssl_required} = connectionSettings; if (connectionSettings.smtp_custom_config) { - config = connectionSettings.smtp_custom_config + config = connectionSettings.smtp_custom_config; } else { config = { host: smtp_host, port: smtp_port, secure: ssl_required, - } + }; } if (this.provider === 'gmail') { const {xoauth2} = connectionCredentials; @@ -139,9 +142,9 @@ module.exports = (sequelize, Sequelize) => { throw new Error("Missing XOAuth2 Token") } const token = this.bearerToken(xoauth2); - config.auth = { user: smtp_username, xoauth2: token } + config.auth = { user: connectionSettings.smtp_username, xoauth2: token } } else if (SUPPORTED_PROVIDERS.has(this.provider)) { - const {smtp_password} = connectionCredentials + const {smtp_username, smtp_password} = connectionCredentials config.auth = { user: smtp_username, pass: smtp_password} } else { throw new Error(`${this.provider} not yet supported`)