Skip to content

Commit

Permalink
Native DKIM capability for emails (#16421)
Browse files Browse the repository at this point in the history
### What does it do?
Adding native DKIM capabilities to MODX without creating a custom email
script. After setting up the correct values in system settings, all mail
sent by MODx will be signed.

### Why is it needed?
More and more companies moving to DKIM and also using 2-factor
authentication for email accounts, so even secure SMTP is not an option
for those. SPF record is often not enough to be able to deliver email
reliably.

### How to test
Regular mail and SMTP should work like before. If you add DKIM details
in settings the Emailer should use it and the email should be signed
with the correct key.

### Related issue(s)/PR(s)
Resolves #16396

---------

Co-authored-by: Joshua Lückers - Jacobsen <joshualuckers@me.com>
  • Loading branch information
krisznet and JoshuaLuckers authored May 29, 2024
1 parent f88ed90 commit 28b4032
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
55 changes: 55 additions & 0 deletions _build/data/transport.core.system_settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,61 @@
'area' => 'mail',
'editedon' => null,
], '', true, true);

$settings['mail_dkim_selector'] = $xpdo->newObject(modSystemSetting::class);
$settings['mail_dkim_selector']->fromArray([
'key' => 'mail_dkim_selector',
'value' => '',
'xtype' => 'textfield',
'namespace' => 'core',
'area' => 'mail',
'editedon' => null,
], '', true, true);
$settings['mail_dkim_identity'] = $xpdo->newObject(modSystemSetting::class);
$settings['mail_dkim_identity']->fromArray([
'key' => 'mail_dkim_identity',
'value' => '',
'xtype' => 'textfield',
'namespace' => 'core',
'area' => 'mail',
'editedon' => null,
], '', true, true);
$settings['mail_dkim_domain'] = $xpdo->newObject(modSystemSetting::class);
$settings['mail_dkim_domain']->fromArray([
'key' => 'mail_dkim_domain',
'value' => '',
'xtype' => 'textfield',
'namespace' => 'core',
'area' => 'mail',
'editedon' => null,
], '', true, true);
$settings['mail_dkim_privatekeyfile'] = $xpdo->newObject(modSystemSetting::class);
$settings['mail_dkim_privatekeyfile']->fromArray([
'key' => 'mail_dkim_privatekeyfile',
'value' => '',
'xtype' => 'textfield',
'namespace' => 'core',
'area' => 'mail',
'editedon' => null,
], '', true, true);
$settings['mail_dkim_privatekeystring'] = $xpdo->newObject(modSystemSetting::class);
$settings['mail_dkim_privatekeystring']->fromArray([
'key' => 'mail_dkim_privatekeystring',
'value' => '',
'xtype' => 'textfield',
'namespace' => 'core',
'area' => 'mail',
'editedon' => null,
], '', true, true);
$settings['mail_dkim_passphrase'] = $xpdo->newObject(modSystemSetting::class);
$settings['mail_dkim_passphrase']->fromArray([
'key' => 'mail_dkim_passphrase',
'value' => '',
'xtype' => 'text-password',
'namespace' => 'core',
'area' => 'mail',
'editedon' => null,
], '', true, true);
$settings['manager_date_format'] = $xpdo->newObject(modSystemSetting::class);
$settings['manager_date_format']->fromArray([
'key' => 'manager_date_format',
Expand Down
18 changes: 18 additions & 0 deletions core/lexicon/en/setting.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,24 @@
$_lang['setting_mail_smtp_user'] = 'SMTP User';
$_lang['setting_mail_smtp_user_desc'] = 'The user to authenticate to SMTP against.';

$_lang['setting_mail_dkim_selector'] = 'DKIM Selector';
$_lang['setting_mail_dkim_selector_desc'] = 'The DKIM domain selector where the public key stored.';

$_lang['setting_mail_dkim_identity'] = 'DKIM Identity';
$_lang['setting_mail_dkim_identity_desc'] = 'DKIM identity you\'re signing as - usually your From address';

$_lang['setting_mail_dkim_domain'] = 'DKIM Domain';
$_lang['setting_mail_dkim_domain_desc'] = 'DKIM signing domain name.';

$_lang['setting_mail_dkim_privatekeyfile'] = 'DKIM Private key file';
$_lang['setting_mail_dkim_privatekeyfile_desc'] = 'DKIM private key file path. You can use DKIM Private key string instead of this.';

$_lang['setting_mail_dkim_privatekeystring'] = 'DKIM Private key string';
$_lang['setting_mail_dkim_privatekeystring_desc'] = 'Takes precedence over DKIM Private key file.';

$_lang['setting_mail_dkim_passphrase'] = 'DKIM Passphrase';
$_lang['setting_mail_dkim_passphrase_desc'] = 'Used only if your key is encrypted.';

$_lang['setting_main_nav_parent'] = 'Main menu parent';
$_lang['setting_main_nav_parent_desc'] = 'The container used to pull all records for the main menu.';

Expand Down
6 changes: 6 additions & 0 deletions core/src/Revolution/Mail/modMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ public function getDefaultAttributes(array $attributes = [])
$default[modMail::MAIL_SMTP_TIMEOUT] = $this->modx->getOption('mail_smtp_timeout', null, 10);
$default[modMail::MAIL_SMTP_USER] = $this->modx->getOption('mail_smtp_user', null, '');
}
$default[modMail::MAIL_DKIM_SELECTOR] = $this->modx->getOption('mail_dkim_selector', null, '');
$default[modMail::MAIL_DKIM_IDENTITY] = $this->modx->getOption('mail_dkim_identity', null, '');
$default[modMail::MAIL_DKIM_DOMAIN] = $this->modx->getOption('mail_dkim_domain', null, '');
$default[modMail::MAIL_DKIM_PRIVATEKEYFILE] = $this->modx->getOption('mail_dkim_privatekeyfile', null, '');
$default[modMail::MAIL_DKIM_PRIVATEKEYSTRING] = $this->modx->getOption('mail_dkim_privatekeystring', null, '');
$default[modMail::MAIL_DKIM_PASSPHRASE] = $this->modx->getOption('mail_dkim_passphrase', null, '');
$default[modMail::MAIL_CHARSET] = $this->modx->getOption('mail_charset', null, 'UTF-8');
$default[modMail::MAIL_ENCODING] = $this->modx->getOption('mail_encoding', null, '8bit');

Expand Down

0 comments on commit 28b4032

Please sign in to comment.