Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Dynamic smtp config require server restart to reflect changes #3282

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/email-plugin/src/sender/nodemailer-email-sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,29 @@ export class NodemailerEmailSender implements EmailSender {
}

private getSmtpTransport(options: SMTPTransportOptions) {
if (!this._smtpTransport) {
if (!this._smtpTransport ||
JSON.stringify(this._smtpTransport?.options) !== JSON.stringify(options)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there is a theoretical risk here with calling JSON.stringify on the options object could throw an error if there is a circular data structure in the object. I'm not sure but the options object can potentially include some complex structures like connection and socket and tls.

So it would be safer to extract a function for comparing these stringified objects which wraps the stringification in a try-catch block.

) {
(options as any).logger = options.logging ? this.createLogger() : false;
this._smtpTransport = createTransport(options);
}
return this._smtpTransport;
}

private getSesTransport(options: SESTransportOptions) {
if (!this._sesTransport) {
if (!this._sesTransport ||
JSON.stringify(this._sesTransport?.options) !== JSON.stringify(options)
) {
this._sesTransport = createTransport(options);
}
return this._sesTransport;
}

private getSendMailTransport(options: SendmailTransportOptions) {
if (!this._sendMailTransport) {
if (!this._sendMailTransport ||
JSON.stringify(this._sendMailTransport?.options) !==
JSON.stringify({ sendmail: true, ...options })
) {
this._sendMailTransport = createTransport({ sendmail: true, ...options });
}
return this._sendMailTransport;
Expand Down
Loading