craigpaul / laravel-postmark

A Postmark adapter for Laravel
MIT License
204 stars 23 forks source link

Ability to use different servers #95

Closed mvdnbrk closed 2 years ago

mvdnbrk commented 3 years ago

Postmark uses the concept of servers. Each server has its own api token.

At the moment there is only one way to set this api token, with POSTMARK_SECRET env variable.

If an app requires sending messages to different servers this can not be done easily.

We should add the ability to set the api token on the fly.

RPillz commented 2 years ago

I needed this feature for a project, and was able to get it working. For clarity, this does remove some of the fall-back values in the base code. (see PostmarkServiceProvider.php line 29)

use Coconuts\Mail\PostmarkTransport;
use GuzzleHttp\Client as HttpClient;

// This updates the postmark server just before sending.

app('mail.manager')->extend('postmark', function () {
    return new PostmarkTransport(
        new HttpClient(config('postmark.guzzle')),
        'CUSTOM-POSTMARK-SERVER-KEY'
    );
});

Mail::to(auth()->user())->send(new \App\Mail\Test($mergedata));
craigpaul commented 2 years ago

I'm going to remove this from the 3.x milestone as we don't necessarily need this to be ready to go before Laravel 9.0 is released.