Skip to content

Commit

Permalink
Added default mail for local setup
Browse files Browse the repository at this point in the history
  • Loading branch information
iwasherefirst2 committed Sep 10, 2019
1 parent 558f343 commit fcb2065
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,35 @@ i.e. they are either send explicitly be the `queue` method or the mailable class

It is of course necessary to install a [queue driver](https://laravel.com/docs/5.8/queues#driver-prerequisites).


### Default mails

It is recommended to **avoid** putting your actual mail credentials into your local `.env` to prevent sending testing mails to actual users.
Instead of adding fake entries in your `.env` file for any mail provided in `config/multimail.php`, simply use a fallback mail that should
be used whenever the username/password cannot be found in the `.env` file. To do so, add a `default` entry inside the `email` array from `config/multimail.php`:

'emails' => [
'[email protected]' =>
[
'pass' => env('first_mail_password'),
'username' => env('first_mail_username'),
'from' => "Max Musterman",
],
'[email protected]' =>
[
'pass' => env('second_mail_password'),
'username' => env('second_mail_username'),
'from' => "Alice Armania",
],
'default' =>
[
'pass' => env('MAIL_PASSWORD'),
'username' => env('MAIL_USERNAME'),
]
],



### Bulk messages

For bulk messages, you may first require a mailer object. You can define a pause in seconds ($timeout) after a number of mails ($frequency) has been send.
Expand Down
11 changes: 4 additions & 7 deletions src/MultiMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ public static function getMailer($name, $timout = null, $frequency = null)
$name = $name['email'];
}


$config = config('multimail.emails')[$name];
if(empty($name) or empty($config))
if(empty($name) || empty($config) || empty($config['pass']) || empty($config['username']))
{
throw new \Exception("Configuration for email: " . $name . ' is missing in config/multimail.php', 1);
$config = config('multimail.emails.default');

if(empty($config) || empty($config['pass']) || empty($config['username'])) throw new \Exception("Configuration for email: " . $name . ' is missing in config/multimail.php and no default is specified.', 1);

}

Expand All @@ -57,10 +58,6 @@ public static function getMailer($name, $timout = null, $frequency = null)
return call_user_func_array($config['function_call'], $config['function_pars']);
}

if(empty($config['pass']) || empty($config['username'])){
throw new \Exception("Username or password is empty for mail provider " . $name, 1);
}

$provider = (!empty($config['provider'])) ? $config['provider'] : config('multimail.provider.default');

//https://stackoverflow.com/a/56965347/2311074
Expand Down

0 comments on commit fcb2065

Please sign in to comment.