Skip to content

Commit

Permalink
Do not require credentials with log driver
Browse files Browse the repository at this point in the history
When log driver where used, exception where thrown
when user/pass were missing. Since there are not
needed for log driver, this exception won't be thrown
in this case any longer.
  • Loading branch information
iwasherefirst2 committed Oct 22, 2019
1 parent 8c52bf2 commit c3926ca
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/MultiMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,15 @@ public static function getMailer($key, $timeout = null, $frequency = null)
$email = $key;
}

$config = config('multimail.emails')[$email];
$config = config('multimail.emails')[$email];

if (empty($email) || empty($config) || empty($config['pass']) || empty($config['username'])) {
$config = config('multimail.emails.default');

if (empty($config) || empty($config['pass']) || empty($config['username'])) {
$provider = static::getProvider($config['provider'] ?? null);

if ($provider['driver'] != 'log' && (empty($config) || empty($config['pass']) || empty($config['username']))) {
// No need for pass/username when using log-driver
throw new \Exception('Configuration for email: ' . $email . ' is missing in config/multimail.php and no default is specified.', 1);
}
}
Expand Down Expand Up @@ -201,7 +205,7 @@ protected static function getLogTransport()
*/
protected static function getSwiftMailer($config, $timeout = null, $frequency = null)
{
$provider = (!empty($config['provider'])) ? $config['provider'] : config('multimail.provider.default');
$provider = static::getProvider($config['provider'] ?? null);

if (isset($provider['driver']) && $provider['driver'] == 'log') {
$transport = static::getLogTransport();
Expand All @@ -219,4 +223,23 @@ protected static function getSwiftMailer($config, $timeout = null, $frequency =

return $swift_mailer;
}

/**
* Get array of provdier (Host/Port/Encyption/Driver).
* If no provider specified, use default.
* @param string provider
* @return array
*/
protected static function getProvider($provider = null)
{
if (!empty($provider)) {
$provider = config('multimail.provider.' . $provider);

if (!empty($provider)) {
return $provider;
}
}

return config('multimail.provider.default');
}
}

0 comments on commit c3926ca

Please sign in to comment.