Fixes for Email plugin

This commit is contained in:
Dmitry Khomutov 2016-08-17 21:20:07 +07:00
commit 4b7ca0b5f9
2 changed files with 36 additions and 75 deletions

View file

@ -39,23 +39,28 @@ class MailerFactory
*/
public function getSwiftMailerFromConfig()
{
$encryptionType = $this->getMailConfig('smtp_encryption');
if ($this->getMailConfig('smtp_address')) {
$encryptionType = $this->getMailConfig('smtp_encryption');
// Workaround issue where smtp_encryption could == 1 in the past by
// checking it is a valid transport
if ($encryptionType && !in_array($encryptionType, stream_get_transports())) {
$encryptionType = null;
// Workaround issue where smtp_encryption could == 1 in the past by
// checking it is a valid transport
if ($encryptionType && !in_array($encryptionType, stream_get_transports())) {
$encryptionType = null;
}
/** @var \Swift_SmtpTransport $transport */
$transport = \Swift_SmtpTransport::newInstance(
$this->getMailConfig('smtp_address'),
$this->getMailConfig('smtp_port'),
$encryptionType
);
$transport->setUsername($this->getMailConfig('smtp_username'));
$transport->setPassword($this->getMailConfig('smtp_password'));
} else {
$transport = \Swift_MailTransport::newInstance();
}
/** @var \Swift_SmtpTransport $transport */
$transport = \Swift_SmtpTransport::newInstance(
$this->getMailConfig('smtp_address'),
$this->getMailConfig('smtp_port'),
$encryptionType
);
$transport->setUsername($this->getMailConfig('smtp_username'));
$transport->setPassword($this->getMailConfig('smtp_password'));
return \Swift_Mailer::newInstance($transport);
}
@ -73,7 +78,7 @@ class MailerFactory
switch ($configName) {
case 'smtp_address':
return "localhost";
return "";
case 'default_mailto_address':
return null;
case 'smtp_port':