Specify the sender email in Gmail and Smtp notifier configuration
Sender email address can now be specified in configuration and applies to GMail notifier and SMTP notifier.pull/137/head
parent
d5035b8704
commit
1ab09b71d4
|
@ -204,6 +204,7 @@ notifier:
|
|||
# gmail:
|
||||
# username: user@example.com
|
||||
# password: yourpassword
|
||||
# sender: admin@example.com
|
||||
|
||||
# Use a SMTP server for sending notifications
|
||||
smtp:
|
||||
|
@ -212,3 +213,4 @@ notifier:
|
|||
secure: false
|
||||
host: 'smtp'
|
||||
port: 1025
|
||||
sender: admin@example.com
|
|
@ -166,6 +166,7 @@ notifier:
|
|||
# gmail:
|
||||
# username: user@example.com
|
||||
# password: yourpassword
|
||||
# sender: admin@example.com
|
||||
|
||||
# Use a SMTP server for sending notifications
|
||||
smtp:
|
||||
|
@ -174,4 +175,4 @@ notifier:
|
|||
secure: false
|
||||
host: 'smtp'
|
||||
port: 1025
|
||||
|
||||
sender: admin@example.com
|
||||
|
|
|
@ -121,7 +121,7 @@ export function get_start_validation(handler: IdentityValidable, postValidationE
|
|||
const host = req.get("Host");
|
||||
const link_url = util.format("https://%s%s?identity_token=%s", host, postValidationEndpoint, token);
|
||||
logger.info(req, "Notification sent to user \"%s\"", identity.userid);
|
||||
return notifier.notify(identity, handler.mailSubject(), link_url);
|
||||
return notifier.notify(identity.email, handler.mailSubject(), link_url);
|
||||
})
|
||||
.then(function () {
|
||||
handler.preValidationResponse(req, res);
|
||||
|
|
|
@ -69,6 +69,7 @@ interface SessionCookieConfiguration {
|
|||
export interface GmailNotifierConfiguration {
|
||||
username: string;
|
||||
password: string;
|
||||
sender: string;
|
||||
}
|
||||
|
||||
export interface SmtpNotifierConfiguration {
|
||||
|
@ -77,6 +78,7 @@ export interface SmtpNotifierConfiguration {
|
|||
host: string;
|
||||
port: number;
|
||||
secure: boolean;
|
||||
sender: string;
|
||||
}
|
||||
|
||||
export interface FileSystemNotifierConfiguration {
|
||||
|
|
|
@ -10,15 +10,14 @@ import BluebirdPromise = require("bluebird");
|
|||
const email_template = Fs.readFileSync(Path.join(__dirname, "../../resources/email-template.ejs"), "UTF-8");
|
||||
|
||||
export abstract class AbstractEmailNotifier implements INotifier {
|
||||
|
||||
notify(identity: Identity, subject: string, link: string): BluebirdPromise<void> {
|
||||
notify(to: string, subject: string, link: string): BluebirdPromise<void> {
|
||||
const d = {
|
||||
url: link,
|
||||
button_title: "Continue",
|
||||
title: subject
|
||||
};
|
||||
return this.sendEmail(identity.email, subject, Ejs.render(email_template, d));
|
||||
return this.sendEmail(to, subject, Ejs.render(email_template, d));
|
||||
}
|
||||
|
||||
abstract sendEmail(email: string, subject: string, content: string): BluebirdPromise<void>;
|
||||
abstract sendEmail(to: string, subject: string, content: string): BluebirdPromise<void>;
|
||||
}
|
|
@ -13,9 +13,9 @@ export class FileSystemNotifier implements INotifier {
|
|||
this.filename = options.filename;
|
||||
}
|
||||
|
||||
notify(identity: Identity, subject: string, link: string): BluebirdPromise<void> {
|
||||
const content = util.format("Date: %s\nUser: %s\nSubject: %s\nLink: %s", new Date().toString(), identity.userid,
|
||||
subject, link);
|
||||
notify(to: string, subject: string, link: string): BluebirdPromise<void> {
|
||||
const content = util.format("Date: %s\nEmail: %s\nSubject: %s\nLink: %s",
|
||||
new Date().toString(), to, subject, link);
|
||||
const writeFilePromised: any = BluebirdPromise.promisify(Fs.writeFile);
|
||||
return writeFilePromised(this.filename, content);
|
||||
}
|
||||
|
|
|
@ -7,16 +7,18 @@ import { IMailSender } from "./IMailSender";
|
|||
|
||||
export class GMailNotifier extends AbstractEmailNotifier {
|
||||
private mailSender: IMailSender;
|
||||
private sender: string;
|
||||
|
||||
constructor(options: GmailNotifierConfiguration, mailSender: IMailSender) {
|
||||
super();
|
||||
this.mailSender = mailSender;
|
||||
this.sender = options.sender;
|
||||
}
|
||||
|
||||
sendEmail(email: string, subject: string, content: string) {
|
||||
sendEmail(to: string, subject: string, content: string) {
|
||||
const mailOptions = {
|
||||
from: "authelia@authelia.com",
|
||||
to: email,
|
||||
from: this.sender,
|
||||
to: to,
|
||||
subject: subject,
|
||||
html: content
|
||||
};
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
|
||||
import * as BluebirdPromise from "bluebird";
|
||||
import { Identity } from "../../../types/Identity";
|
||||
|
||||
export interface INotifier {
|
||||
notify(identity: Identity, subject: string, link: string): BluebirdPromise<void>;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
import * as BluebirdPromise from "bluebird";
|
||||
|
||||
export interface INotifier {
|
||||
notify(to: string, subject: string, link: string): BluebirdPromise<void>;
|
||||
}
|
|
@ -8,17 +8,19 @@ import { SmtpNotifierConfiguration } from "../configuration/Configuration";
|
|||
|
||||
export class SmtpNotifier extends AbstractEmailNotifier {
|
||||
private mailSender: IMailSender;
|
||||
private sender: string;
|
||||
|
||||
constructor(options: SmtpNotifierConfiguration,
|
||||
mailSender: IMailSender) {
|
||||
super();
|
||||
this.mailSender = mailSender;
|
||||
this.sender = options.sender;
|
||||
}
|
||||
|
||||
sendEmail(email: string, subject: string, content: string) {
|
||||
sendEmail(to: string, subject: string, content: string) {
|
||||
const mailOptions = {
|
||||
from: "authelia@authelia.com",
|
||||
to: email,
|
||||
from: this.sender,
|
||||
to: to,
|
||||
subject: subject,
|
||||
html: content
|
||||
};
|
||||
|
|
|
@ -55,7 +55,8 @@ describe("test server configuration", function () {
|
|||
notifier: {
|
||||
gmail: {
|
||||
username: "user@example.com",
|
||||
password: "password"
|
||||
password: "password",
|
||||
sender: "test@authelia.com"
|
||||
}
|
||||
},
|
||||
regulation: {
|
||||
|
|
|
@ -36,7 +36,8 @@ describe("test config adapter", function () {
|
|||
notifier: {
|
||||
gmail: {
|
||||
username: "user",
|
||||
password: "password"
|
||||
password: "password",
|
||||
sender: "admin@example.com"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -84,14 +85,16 @@ describe("test config adapter", function () {
|
|||
yaml_config.notifier = {
|
||||
gmail: {
|
||||
username: "user",
|
||||
password: "pass"
|
||||
password: "pass",
|
||||
sender: "admin@example.com"
|
||||
}
|
||||
};
|
||||
const config = ConfigurationAdapter.adapt(yaml_config);
|
||||
Assert.deepEqual(config.notifier, {
|
||||
gmail: {
|
||||
username: "user",
|
||||
password: "pass"
|
||||
password: "pass",
|
||||
sender: "admin@example.com"
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -33,7 +33,8 @@ describe("test ldap configuration adaptation", function () {
|
|||
notifier: {
|
||||
gmail: {
|
||||
username: "user",
|
||||
password: "password"
|
||||
password: "password",
|
||||
sender: "admin@example.com"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import * as sinon from "sinon";
|
||||
import * as assert from "assert";
|
||||
import * as Assert from "assert";
|
||||
import BluebirdPromise = require("bluebird");
|
||||
|
||||
import { MailSenderStub } from "../mocks/notifiers/MailSenderStub";
|
||||
|
@ -11,24 +11,19 @@ describe("test gmail notifier", function () {
|
|||
const mailSender = new MailSenderStub();
|
||||
const options = {
|
||||
username: "user_gmail",
|
||||
password: "pass_gmail"
|
||||
password: "pass_gmail",
|
||||
sender: "admin@example.com"
|
||||
};
|
||||
|
||||
mailSender.sendStub.returns(BluebirdPromise.resolve());
|
||||
const sender = new GMailNotifier.GMailNotifier(options, mailSender);
|
||||
const subject = "subject";
|
||||
|
||||
const identity = {
|
||||
userid: "user",
|
||||
email: "user@example.com"
|
||||
};
|
||||
|
||||
const url = "http://test.com";
|
||||
|
||||
return sender.notify(identity, subject, url)
|
||||
return sender.notify("user@example.com", subject, url)
|
||||
.then(function () {
|
||||
assert.equal(mailSender.sendStub.getCall(0).args[0].to, "user@example.com");
|
||||
assert.equal(mailSender.sendStub.getCall(0).args[0].subject, "subject");
|
||||
Assert.equal(mailSender.sendStub.getCall(0).args[0].to, "user@example.com");
|
||||
Assert.equal(mailSender.sendStub.getCall(0).args[0].subject, "subject");
|
||||
return BluebirdPromise.resolve();
|
||||
});
|
||||
});
|
||||
|
@ -37,24 +32,20 @@ describe("test gmail notifier", function () {
|
|||
const mailSender = new MailSenderStub();
|
||||
const options = {
|
||||
username: "user_gmail",
|
||||
password: "pass_gmail"
|
||||
password: "pass_gmail",
|
||||
sender: "admin@example.com"
|
||||
};
|
||||
|
||||
mailSender.sendStub.returns(BluebirdPromise.reject(new Error("Failed to send mail")));
|
||||
const sender = new GMailNotifier.GMailNotifier(options, mailSender);
|
||||
const subject = "subject";
|
||||
|
||||
const identity = {
|
||||
userid: "user",
|
||||
email: "user@example.com"
|
||||
};
|
||||
|
||||
const url = "http://test.com";
|
||||
|
||||
return sender.notify(identity, subject, url)
|
||||
return sender.notify("user@example.com", subject, url)
|
||||
.then(function () {
|
||||
return BluebirdPromise.reject(new Error());
|
||||
}, function() {
|
||||
Assert.equal(mailSender.sendStub.getCall(0).args[0].from, "admin@example.com");
|
||||
return BluebirdPromise.resolve();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -18,7 +18,8 @@ describe("test MailSenderBuilder", function() {
|
|||
const mailSenderBuilder = new MailSenderBuilder(Nodemailer);
|
||||
mailSenderBuilder.buildGmail({
|
||||
username: "user_gmail",
|
||||
password: "pass_gmail"
|
||||
password: "pass_gmail",
|
||||
sender: "admin@example.com"
|
||||
});
|
||||
Assert.equal(createTransportStub.getCall(0).args[0].auth.user, "user_gmail");
|
||||
Assert.equal(createTransportStub.getCall(0).args[0].auth.pass, "pass_gmail");
|
||||
|
@ -31,7 +32,8 @@ describe("test MailSenderBuilder", function() {
|
|||
password: "password",
|
||||
port: 25,
|
||||
secure: true,
|
||||
username: "user"
|
||||
username: "user",
|
||||
sender: "admin@example.com"
|
||||
});
|
||||
Assert.deepStrictEqual(createTransportStub.getCall(0).args[0], {
|
||||
host: "mail.example.com",
|
||||
|
|
|
@ -15,7 +15,8 @@ describe("test notifier factory", function () {
|
|||
const options = {
|
||||
gmail: {
|
||||
username: "abc",
|
||||
password: "password"
|
||||
password: "password",
|
||||
sender: "admin@example.com"
|
||||
}
|
||||
};
|
||||
mailSenderBuilderStub = new MailSenderBuilderStub();
|
||||
|
@ -29,7 +30,8 @@ describe("test notifier factory", function () {
|
|||
password: "pass",
|
||||
secure: true,
|
||||
host: "localhost",
|
||||
port: 25
|
||||
port: 25,
|
||||
sender: "admin@example.com"
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -54,7 +54,8 @@ describe("Private pages of the server must not be accessible without session", f
|
|||
notifier: {
|
||||
gmail: {
|
||||
username: "user@example.com",
|
||||
password: "password"
|
||||
password: "password",
|
||||
sender: "admin@example.com"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -54,7 +54,8 @@ describe("Public pages of the server must be accessible without session", functi
|
|||
notifier: {
|
||||
gmail: {
|
||||
username: "user@example.com",
|
||||
password: "password"
|
||||
password: "password",
|
||||
sender: "admin@example.com"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue