diff --git a/packages/email/email.js b/packages/email/email.js index 490b8916cb..695bdbb9ed 100644 --- a/packages/email/email.js +++ b/packages/email/email.js @@ -65,10 +65,15 @@ const knownHostsTransport = function(settings = undefined, url = undefined) { host = urlObject.hostname; user = urlObject.username; password = urlObject.password; + } else if (urlObject.protocol && urlObject.username && urlObject.password) { + // We have some data from urlObject + host = urlObject.protocol.split(':')[0]; + user = urlObject.username; + password = urlObject.password; } else { // We need to disect the URL ourselves to get the data // First get rid of the leading '//' and split to username and the rest - const temp = urlObject.pathname.substring(2).split(':'); + const temp = urlObject.pathname.substring(2)?.split(':'); user = temp[0]; // Now we split by '@' to get password and hostname const temp2 = temp[1].split('@'); diff --git a/packages/email/email_tests.js b/packages/email/email_tests.js index e68e64687f..750ed0f24e 100644 --- a/packages/email/email_tests.js +++ b/packages/email/email_tests.js @@ -255,7 +255,7 @@ Tinytest.add("email - alternate API is used for sending gets data", function(tes Meteor.settings.packages = { email: { service: '1on1', user: 'test', password: 'pwd' } }; Email.customTransport = (options) => { test.equal(options.from, 'foo@example.com'); - test.equal(options.settings?.service, '1on1'); + test.equal(options.packageSettings?.service, '1on1'); }; Email.send({ @@ -283,13 +283,13 @@ Tinytest.add("email - URL string for known hosts", function(test) { const outlookTransport2 = EmailTest.knowHostsTransport(undefined, 'Outlook365://firstname.lastname@hotmail.com:password@hotmail.com'); test.equal(outlookTransport.transporter.auth.user, 'firstname.lastname%40hotmail.com'); test.equal(outlookTransport.options.auth.user, 'firstname.lastname%40hotmail.com'); - test.equal(outlookTransport.transporter.options.service, 'hotmail.com'); + test.equal(outlookTransport.transporter.options.service, 'outlook365'); test.equal(outlookTransport2.transporter.auth.user, 'firstname.lastname%40hotmail.com'); - test.equal(outlookTransport2.transporter.options.service, 'hotmail.com'); + test.equal(outlookTransport2.transporter.options.service, 'outlook365'); const hotmailTransport = EmailTest.knowHostsTransport(undefined, 'Hotmail://firstname.lastname@hotmail.com:password@hotmail.com'); console.dir(hotmailTransport); - test.equal(hotmailTransport.transporter.options.service, 'hotmail.com'); + test.equal(hotmailTransport.transporter.options.service, 'hotmail'); const falseService = { service: '1on1', user: 'test', password: 'pwd' }; const errorMsg = 'Could not recognize e-mail service. See list at https://nodemailer.com/smtp/well-known/ for services that we can configure for you.';