ActiveCampaign / swiftmailer-postmark

The Official Swiftmailer Transport for Postmark.
https://postmarkapp.com
53 stars 28 forks source link

Use multiple postmark drivers with stream ID in Laravel application #40

Open christophrumpel opened 3 years ago

christophrumpel commented 3 years ago

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

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 commented 3 years ago

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 commented 3 years ago

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

oxodesign commented 3 years ago

@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('name@example.com')
            ->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

christophrumpel commented 3 years ago

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?

oxodesign commented 3 years ago

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

lightwalkernet commented 3 years ago

@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.

oxodesign commented 2 years ago

@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