Skip to content

Commit

Permalink
Add options.forceAuth for SMTP
Browse files Browse the repository at this point in the history
Re-introduces opt-in behavior that was changed in f419b09
  • Loading branch information
pmalouin authored and andris9 committed Feb 27, 2020
1 parent 705fc8f commit a27ed2f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/smtp-pool/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ class SMTPPool extends EventEmitter {
return;
}

if (auth && connection.allowsAuth) {
if (auth && (connection.allowsAuth || options.forceAuth)) {
connection.login(auth, err => {
if (returned) {
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/smtp-pool/pool-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class PoolResource extends EventEmitter {
return;
}

if (this.auth && this.connection.allowsAuth) {
if (this.auth && (this.connection.allowsAuth || options.forceAuth)) {
this.connection.login(this.auth, err => {
if (returned) {
return;
Expand Down
4 changes: 2 additions & 2 deletions lib/smtp-transport/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class SMTPTransport extends EventEmitter {

let auth = this.getAuth(mail.data.auth);

if (auth && connection.allowsAuth) {
if (auth && (connection.allowsAuth || options.forceAuth)) {
connection.login(auth, err => {
if (auth && auth !== this.auth && auth.oauth2) {
auth.oauth2.removeAllListeners();
Expand Down Expand Up @@ -370,7 +370,7 @@ class SMTPTransport extends EventEmitter {

let authData = this.getAuth({});

if (authData && connection.allowsAuth) {
if (authData && (connection.allowsAuth || options.forceAuth)) {
connection.login(authData, err => {
if (returned) {
return;
Expand Down
28 changes: 28 additions & 0 deletions test/smtp-transport/smtp-tranport-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,34 @@ describe('SMTP Transport Tests', function() {
);
});

it('Should fail auth if forceAuth=true', function(done) {
let client = new SMTPTransport({
port: PORT_NUMBER,
auth: {
user: 'zzz'
},
forceAuth: true,
logger: false
});

client.send(
{
data: {},
message: new MockBuilder(
{
from: '[email protected]',
to: '[email protected]'
},
'message'
)
},
function(err) {
expect(err.code).to.equal('EAUTH');
done();
}
);
});

it('Should send mail', function(done) {
let client = new SMTPTransport('smtp:localhost:' + PORT_NUMBER + '?logger=false');
let chunks = [],
Expand Down

0 comments on commit a27ed2f

Please sign in to comment.