Merge pull request #158 from clems4ever/anonymous-smtp

Allow anonymous user in SMTP notifier
This commit is contained in:
Clément Michaud 2017-10-16 00:09:55 +02:00 committed by GitHub
commit 6e3a9494ce
3 changed files with 43 additions and 22 deletions

View File

@ -73,8 +73,8 @@ export interface GmailNotifierConfiguration {
} }
export interface SmtpNotifierConfiguration { export interface SmtpNotifierConfiguration {
username: string; username?: string;
password: string; password?: string;
host: string; host: string;
port: number; port: number;
secure: boolean; secure: boolean;

View File

@ -28,11 +28,15 @@ export class MailSenderBuilder implements IMailSenderBuilder {
host: options.host, host: options.host,
port: options.port, port: options.port,
secure: options.secure, // upgrade later with STARTTLS secure: options.secure, // upgrade later with STARTTLS
auth: { };
if (options.username && options.password) {
smtpOptions.auth = {
user: options.username, user: options.username,
pass: options.password pass: options.password
}
}; };
}
return new MailSender(smtpOptions, this.nodemailer); return new MailSender(smtpOptions, this.nodemailer);
} }
} }

View File

@ -25,7 +25,8 @@ describe("test MailSenderBuilder", function() {
Assert.equal(createTransportStub.getCall(0).args[0].auth.pass, "pass_gmail"); Assert.equal(createTransportStub.getCall(0).args[0].auth.pass, "pass_gmail");
}); });
it("should create a smtp mail sender", function() { describe("build smtp mail sender", function() {
it("should create a smtp mail sender with authenticated user", function() {
const mailSenderBuilder = new MailSenderBuilder(Nodemailer); const mailSenderBuilder = new MailSenderBuilder(Nodemailer);
mailSenderBuilder.buildSmtp({ mailSenderBuilder.buildSmtp({
host: "mail.example.com", host: "mail.example.com",
@ -45,4 +46,20 @@ describe("test MailSenderBuilder", function() {
secure: true, secure: true,
}); });
}); });
it("should create a smtp mail sender with anonymous user", function() {
const mailSenderBuilder = new MailSenderBuilder(Nodemailer);
mailSenderBuilder.buildSmtp({
host: "mail.example.com",
port: 25,
secure: true,
sender: "admin@example.com"
});
Assert.deepStrictEqual(createTransportStub.getCall(0).args[0], {
host: "mail.example.com",
port: 25,
secure: true,
});
});
});
}); });