Percent-encode SMTP password to prevent URI malformed errors

Fix URIError: URI malformed errors when sending email with SMTP password containing some special characters.
See Sections 2.1 and 3.2 of RFC 3986.
This commit is contained in:
Pierre Kuhner 2017-08-24 15:23:49 +02:00 committed by GitHub
parent 1b40c42cab
commit c99a950979

View file

@ -45,7 +45,7 @@ Settings.helpers({
if (!this.mailServer.username && !this.mailServer.password) {
return `${protocol}${this.mailServer.host}:${this.mailServer.port}/`;
}
return `${protocol}${this.mailServer.username}:${this.mailServer.password}@${this.mailServer.host}:${this.mailServer.port}/`;
return `${protocol}${this.mailServer.username}:encodeURIComponent(${this.mailServer.password})@${this.mailServer.host}:${this.mailServer.port}/`;
},
});
Settings.allow({
@ -84,7 +84,7 @@ if (Meteor.isServer) {
if (!doc.mailServer.username && !doc.mailServer.password) {
process.env.MAIL_URL = `${protocol}${doc.mailServer.host}:${doc.mailServer.port}/`;
} else {
process.env.MAIL_URL = `${protocol}${doc.mailServer.username}:${doc.mailServer.password}@${doc.mailServer.host}:${doc.mailServer.port}/`;
process.env.MAIL_URL = `${protocol}${doc.mailServer.username}:encodeURIComponent(${doc.mailServer.password})@${doc.mailServer.host}:${doc.mailServer.port}/`;
}
Accounts.emailTemplates.from = doc.mailServer.from;
}