swiftmailer-postmark icon indicating copy to clipboard operation
swiftmailer-postmark copied to clipboard

Use multiple postmark drivers with stream ID in Laravel application

Open christophrumpel opened this issue 4 years ago • 7 comments

I'm using a newsletter application (Mailcoach) where you can define two different mail drivers:

  • one for bulk emails
  • one for transx emails

Postmark also suggests sending through different streams.

This package lets you define the "Postmark Message Stream" by adding the stream id to the header. But when you use the postmark driver in Laravel, you only have the option to define the token seen here: https://github.com/laravel/framework/blob/bd67cc22af6fbc1f5745b0e3ce79e0a12b092048/src/Illuminate/Mail/MailManager.php#L325

So even if I create two postmark mail drivers, I could only use a different API token (= 2 different Postmark "servers"), but I cannot define the message stream.

If the above assumptions are correct, I could do a PR on Laravel to also get a headers array from the services.php config file. What do you think?

christophrumpel avatar Dec 29 '20 13:12 christophrumpel

One Addition: I know you can change the mail's header on a per mailable basis. https://laravel.com/docs/8.x/mail#customizing-the-swiftmailer-message

But since Postmark's stream, are almost like a different account, it would behandy to define the stream also on a driver-level.

christophrumpel avatar Dec 29 '20 13:12 christophrumpel

I already created a PR on Laravel. Let's see if it gets merged: https://github.com/laravel/framework/pull/35755

christophrumpel avatar Dec 29 '20 19:12 christophrumpel

@christophrumpel is this working for you? Im running Laravel 8.32.1 and Im trying to send to different stream without any luck.

this is my configuration:

'mailers' => [
        'pm-custom' => [
            'transport' => 'postmark',
            'message_stream_id' => 'custom-stream-id',
        ],
    ],

Trying to test like this:

Mail::mailer('pm-custom')
            ->to('[email protected]')
            ->send(new TestMailable());
            

I also tried to add mailer to the Mailable without any luck, all test emails went to default stream.

All help appreciated

oxodesign avatar Apr 23 '21 06:04 oxodesign

Hey, it is working for but I only tested by using my newsletter software Mailcoach where I can select different mailers.

Here is my config https://github.com/christophrumpel/christoph-rumpel.com/blob/production/config/mail.php#L61-L83 Have you set a token somewhere else?

christophrumpel avatar Apr 23 '21 08:04 christophrumpel

Hmmm. yes under services, but that is what is suggested by the docs. I see you dont have that in your config! Will test by removing it and report back. Thanks for your help

oxodesign avatar Apr 23 '21 08:04 oxodesign

@oxodesign did you get this to work with changing the mailer? For me it continues to send from the default postmark account even if I remove the token from services config which is very strange. Would be grateful for some guidance.

lightwalkernet avatar Aug 25 '21 23:08 lightwalkernet

@oxodesign did you get this to work with changing the mailer? For me it continues to send from the default postmark account even if I remove the token from services config which is very strange. Would be grateful for some guidance.

No, sorry for late reply

oxodesign avatar Dec 02 '21 13:12 oxodesign