hashemi / too-mailable
A Laravel based package for changing `Mail` transport and it's credentials from application layer in runtime. Simple and easy abstraction `Mailable` layer will be provided with this package. Currently this package support only SMTP
Requires
- hashemi/valideto: dev-master
- symfony/amazon-mailer: ^6.1.0
- symfony/google-mailer: ^6.1.0
- symfony/mailchimp-mailer: ^6.1.0
- symfony/mailgun-mailer: ^6.1.0
- symfony/mailjet-mailer: ^6.1.0
- symfony/oh-my-smtp-mailer: ^6.1.0
- symfony/postmark-mailer: ^6.1.0
- symfony/sendgrid-mailer: ^6.1.0
- symfony/sendinblue-mailer: ^6.1.0
Requires (Dev)
- orchestra/testbench: 8.0.x-dev
- overtrue/phplint: 8.1.x-dev
- phpunit/phpunit: ^9.5.10
- symfony/var-dumper: 6.2.x-dev
This package is auto-updated.
Last update: 2024-10-30 01:48:17 UTC
README
A Laravel based package for changing Mail
transport and it's credentials from application layer in runtime. Simple and easy abstraction Mailable
layer will be provided with this package. Currently this package support only SMTP.
Installation
You can start it from composer. Go to your terminal and run this command from your project root directory.
composer require hashemi/laravel-too-mailable
- If you're using Laravel, then Laravel will automatically discover the package. In case it doesn't discover the package then add the following provider in your
config/app.php
's providers array.
Hashemi\TooMailable\TooMailableServiceProvider::class
Usage
This package will be provide TooMailable
abstract class and you need to use your mail class. This abstract class has two abstract method.
-
transport(): string|EsmtpTransport
This method will be return package supported transport by string or custom transport class which will beEsmtpTransport
inherited. -
credentials(): array
This method will be return necessary credentials of current transport.
Example:
use Hashemi\TooMailable\TooMailable; class SendVerificatioMail extends TooMailable { //... public function transport() { return 'amazon'; } public function credentials() { return [ 'username' => 'my-user', 'password' => 'password-123', 'region' => 'us-east-2' ]; } }
This package is also contain a config where each built-in transport class is configured. If anyone needs to override that transport they can easily do it by publish config from vendor. Config file will be stored in config/too-mailable.php
on your application.
Example:
use Hashemi\TooMailable\Transports\{ Amazon, Google, Mailchimp, Mailgun, Mailjet, OhMySmtp, Postmark, Sendgrid, SendInBlue }; return [ 'transports' => [ 'amazon' => Amazon::class, 'google' => Google::class, 'mailchimp' => Mailchimp::class, 'mailgun' => Mailgun::class, 'mailjet' => Mailjet::class, 'postmark' => Postmark::class, 'sendgrid' => Sendgrid::class, 'sendinblue' => SendInBlue::class, 'oh-my-smtp' => OhMySmtp::class, ], ];
So if you want to change exists transport then,
return [ 'transports' => [ //... 'amazon' => MyNewAmazonTransport::class, ], ];
Or, if you want to add new transport then,
return [ 'transports' => [ //... 'converkit' => MyNewConvertKit::class ], ];
But MyNewConvertKit
class should be implements Hashemi\TooMailable\Interfaces\TransportInterface
interface. Credentials will be passed through __construct
function of MyNewConvertKit
class.
Contributing
Pull requests are welcome. For any changes, please open an issue first to discuss what you would like to change.