netglue / laminas-postmark-transport
Mail transport using Postmark's API for applications using laminas components for email
Installs: 18 969
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 3
Forks: 0
Open Issues: 6
Requires
- php: ~8.1 || ~8.2 || ~8.3
- laminas/laminas-mail: ^2.11.0
- laminas/laminas-mime: ^2.9.1
- laminas/laminas-validator: ^2.23.0
- myclabs/php-enum: ^1.8.4
- netglue/laminas-mail-utils: ^0
- netglue/psr-container-postmark: ^1.6.0
- psr/cache: ^1.0 || ^2.0.0 || ^3.0.0
- wildbit/postmark-php: ^4.0
Requires (Dev)
- doctrine/coding-standard: ^12.0
- laminas/laminas-config-aggregator: ^1.14
- laminas/laminas-servicemanager: ^3.22.1
- phpunit/phpunit: ^10.5.5
- psalm/plugin-phpunit: ^0.18.4
- roave/security-advisories: dev-latest
- symfony/cache: ^5.4.15 || ^6.4.2 || ^7.0
- vimeo/psalm: ^5.18
Conflicts
- guzzlehttp/guzzle: ^6.0
- 1.5.x-dev
- 1.4.x-dev
- 1.4.0
- 1.3.x-dev
- 1.3.0
- 1.2.x-dev
- 1.2.0
- 1.1.x-dev
- 1.1.0
- 1.0.x-dev
- 1.0.0
- 0.8.x-dev
- 0.8.0
- 0.7.0
- 0.6.0
- 0.5.0
- 0.4.0
- 0.3.0
- 0.2.0
- 0.1.0
- 0.0.1
- 0.0.0
- dev-renovate/laminas-laminas-validator-3.x
- dev-renovate/lock-file-maintenance
- dev-renovate/wildbit-postmark-php-6.x
- dev-renovate/laminas-laminas-servicemanager-4.x
- dev-renovate/phpunit-phpunit-11.x
This package is auto-updated.
Last update: 2024-12-22 06:16:09 UTC
README
Introduction
This lib provides a mail transport for use with Laminas\Mail and Postmark’s transactional email service. It also provides email message validators to help make sure that messages you send via Postmark are acceptable - I'm quite pleased with the validator that checks the from address is listed in the verified postmark domains on your account, or amongst the configured sender signatures.
Installation
composer require netglue/laminas-postmark-transport
If you are using this in an app built with Expressive/Mezzio then the config provider should get injected automatically for you during installation by way of the Laminas component installer. If you're using Laminas MVC then you might have to take extra steps to get the default config fired up.
One of the dependencies is a tiny package netglue/psr-container-postmark - this is what's used to configure the official Postmark API client so you can find some additional info in the README in that lib for configuring your account and server tokens for the service.
Usage
By default, assuming use of Laminas Service Manager for your DIC, you will be able to retrieve your transport using either:
$transport = $container->get(\Laminas\Mail\Transport\TransportInterface::class); // or $transport = $container->get(\Netglue\Mail\Postmark\Transport\PostmarkTransport::class);
As with all mail transports, you'll only interact with it to send a Laminas\Mail\Message
:
$message = new Message(); // ... Set To, From, Subject etc... $transport->send($message);
Read up on the docs specific to sending mail with Laminas components here...
The main reason that I put this lib together is so that I could validate messages before dispatching them to the API to surface common errors such as an invalid sender address, too many recipients etc. The transport accepts a validator in its constructor arguments that is used to enforce the constraints placed on sending mail with Postmark specifically.
There is a default validator chain that you can inspect covering most of these constraints and a shipped FromAddressValidator that is not used by default. The reason this one isn't initially enabled is because it makes API calls to the account endpoints to retrieve the configured sending domains and email addresses and then checks that the From header of the message is amongst the verified senders.
So, to use this validator, you'd need to:
- Configure the access token for the account API
- Inject a different validator chain into the transport
- Provide the name of a PSR-6 compatible cache that can be retrieved from the container
Hopefully the following configuration should illuminate what's required...
'postmark' => [ 'server_token' => 'Your "server" token for sending mail', 'account_token' => 'Token for the account API', // Required when using the sender validator 'message_validator' => \MyApp\Validator\CustomMessageValidationChain::class, 'cache_service' => \MyApp\PsrCacheItemPool::class, // The cache to use for the domain and sender signatures list. ],
Finally, this lib also has a dependency on netglue/laminas-mail-utils which is primarily a collection of more generic validators for mail messages and message behaviours that are intended for use with other vendors such as SparkPost, MailGun etc. If/when you build your custom validator chain, there are a bunch of validators there that might be useful.