Skip to content

Commit c306e4f

Browse files
committed
fix(notifications): this.fromAddress is undefined for custom transports as it is only constructed after custom transport is initialized.
1 parent 30a2762 commit c306e4f

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

packages/notifications/src/drivers/MailNotification.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,23 @@ export class MailNotification extends NotificationContract {
4444
* Prepare the mail driver so we can use it to relay the message
4545
*/
4646
private async prepareDriver() {
47+
const options = this.options
48+
49+
this.fromAddress =
50+
options.from ??
51+
this.driverConfig.from ??
52+
env('MAIL_FROM_ADDRESS', 'no-reply@example.com')
53+
4754
if (typeof this.transport !== 'string') {
4855
this.driver = nodemailer.createTransport(this.transport)
4956

5057
return
5158
}
5259

53-
const options = this.options
5460
const transport = configure(`transports.${this.transport}`, {}) as MergedTransportConfig
5561

62+
this.fromAddress = transport.from || this.fromAddress
63+
5664
/**
5765
* Setup nodemailer to stream messages so we can store the mail to file
5866
*/
@@ -62,12 +70,6 @@ export class MailNotification extends NotificationContract {
6270
transport.directory ??
6371
env('MAIL_FILE_PATH', join(Arkstack.rootDir(), './storage/framework/mails'))
6472

65-
this.fromAddress =
66-
options.from ??
67-
this.driverConfig.from ??
68-
transport.from ??
69-
env('MAIL_FROM_ADDRESS', 'no-reply@example.com')
70-
7173
this.driver = nodemailer.createTransport({
7274
streamTransport: true,
7375
buffer: true,
@@ -133,12 +135,6 @@ export class MailNotification extends NotificationContract {
133135
transport.pass ??
134136
env('MAIL_PASSWORD', '')
135137

136-
this.fromAddress =
137-
options.from ??
138-
this.driverConfig.from ??
139-
transport.from ??
140-
env('MAIL_FROM_ADDRESS', 'no-reply@example.com')
141-
142138
this.driver = nodemailer.createTransport({
143139
url: transport.url ?? options.url ?? env('MAIL_URL'),
144140
host: options.host ?? transport.host ?? env('MAIL_HOST', 'localhost'),

0 commit comments

Comments
 (0)