Skip to content

Commit

Permalink
feature(mail): add smtp support
Browse files Browse the repository at this point in the history
This PR adds support for the Zend Sendmail transport
Closes #12938
  • Loading branch information
thatnerdjosh committed Jan 23, 2020
1 parent 159fc15 commit ada8bb7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
31 changes: 31 additions & 0 deletions elgg-config/settings.example.php
Expand Up @@ -377,6 +377,37 @@
*/
//$CONFIG->image_processor = 'imagick';


/**
* Configure emailer transport
*
* This setting can be used to select a different emailer transport. By default the Zend Sendmail Transport is used.
* Currently only 'smtp' and 'sendmail' are supported as a different configuration.
* For 'smtp', the SMTP server's settings must be set, while 'sendmail' requires no configuration.
*
* @global string $CONFIG->emailer_transport
*/
//$CONFIG->emailer_transport = 'sendmail';

/**
* Configure emailer SMTP settings
*
* This setting is only necessary if the above emailer transport is set to 'smtp'.
* Please refer to https://docs.zendframework.com/zend-mail/transport/smtp-authentication/#examples
*/
//$CONFIG->emailer_smtp_settings = array(
// 'name' => 'localhost.localdomain',
// 'host' => '127.0.0.1',
// 'connection_class' => 'login',
// 'connection_config' => [
// 'username' => 'user',
// 'password' => 'pass',
// 'ssl' => '', // OPTIONAL (tls or ssl)
// 'port' => '', // OPTIONAL (Non-SSL default 25, SSL default 465, TLS default 587)
// 'use_complete_quit' => '', // OPTIONAL
// ],
//);

/**
* Logging level
*
Expand Down
2 changes: 2 additions & 0 deletions engine/classes/Elgg/Config.php
Expand Up @@ -54,6 +54,8 @@
* @property string $elgg_settings_file
* @property bool $elgg_config_set_secret
* @property bool $enable_profiling
* @property string $emailer_transport This is an override for Elgg's default email handling transport (default sendmail)
* @property array $emailer_smtp_settings This configures SMTP if $emailer_transport is set to "smtp"
* @property mixed $embed_tab
* @property string $exception_include This is an optional script used to override Elgg's default handling of uncaught exceptions.
* @property string[] $group
Expand Down
14 changes: 13 additions & 1 deletion engine/classes/Elgg/Di/ServiceProvider.php
Expand Up @@ -481,7 +481,19 @@ public function __construct(Config $config) {
return $logger;
});

$this->setClassName('mailer', 'Zend\Mail\Transport\Sendmail');
$this->setFactory('mailer', function(ServiceProvider $c) {
switch ($c->config->emailer_transport) {
case 'smtp':
$transport = new \Zend\Mail\Transport\Smtp();
$transportOptions = new \Zend\Mail\Transport\SmtpOptions(
$c->config->emailer_smtp_settings
);
$transport->setOptions($transportOptions);
return $transport;
default:
return new \Zend\Mail\Transport\Sendmail();
}
});

$this->setFactory('menus', function(ServiceProvider $c) {
return new \Elgg\Menu\Service($c->hooks, $c->config);
Expand Down

0 comments on commit ada8bb7

Please sign in to comment.