Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/eseperio/yii2-email-accounts-manager

Use and manage different email accounts under the same project.
https://github.com/eseperio/yii2-email-accounts-manager

Last synced: 2 months ago
JSON representation

Use and manage different email accounts under the same project.

Awesome Lists containing this project

README

        

# yii2-email-accounts-manager

Use and manage different email accounts under the same project.
Features methods to live test the configuration and ensure it is correct.

### Features

- Manage multiple email accounts
- SMTP + IMAP configuration
- SMTP + IMAP live test
- Autodiscover SMTP and IMAP settings (when available)

## Installation

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

`composer require eseperio/yii2-email-accounts-manager`

`ext-simplexml` is required for autodiscover feature, but has not been required within composer.json so you can use the
library without autodiscover

Add the migration path to your console config:

```php
return [
'controllerMap' => [
'migrate' => [
'class' => 'yii\console\controllers\MigrateController',
'migrationPath' => [
'@vendor/eseperio/yii2-email-accounts-manager/src/migrations',
],
],
],
];
```

Add the module to your app modules configuration

```php
return [
'modules' => [
'email-manager' =>[
'class'=> \eseperio\emailManager\EmailManagerModule::class,
'showImapSettings' => false, // change if you need imap settings to be shown,
// 'mailer'=> 'mailer',
// 'transport => ['class' => 'Swift_SmtpTransport'],
],

]
]
```

## Usage

Important: This module will replace the current transport for the mailer defined and it does not restore to previous value.
If you want to prevent this use a different mailer component for this module.

This module includes methods for checking whether the email account is valid and for sending emails using the given
configuration.

The EmailAccount model includes useful methods, like `getTransport()` and `setAsMainTransport()`.

`getTransport()` returns the transport configuration based on configuration defined within module and the account
itself.

`setAsMainTransport()` will set the transport configuration for the mailer component defined in the module configuration
and will return the mailer instance.
`compose($view='',$params=[])` will return a new message instance preconfigured with the transport configuration for the
account and also `setFrom` defined with the account address.

### Sending an email from a custom account

```php
use eseperio\emailmanager\models\EmailAccount;

$account = EmailAccount::findOne(1)->compose('test', ['message' => 'Hello world!'])->setTo('[email protected]')->send();
```