Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using DKIM to send mail with Thelia2 ( core/lib/Thelia/Mailer/MailerFactory.php )
diff --git i/core/lib/Thelia/Mailer/MailerFactory.php w/core/lib/Thelia/Mailer/MailerFactory.php
index a59ad40..7808a79 100644
--- i/core/lib/Thelia/Mailer/MailerFactory.php
+++ w/core/lib/Thelia/Mailer/MailerFactory.php
@@ -30,6 +30,12 @@ use Thelia\Model\MessageQuery;
*/
class MailerFactory
{
+ // {{{ added by @asenar - DKIM patch
+ // HOWTO
+ // 1) install opendkim opendkim-tools
+ // follow instruction on this tutorial https://blog.hbis.fr/2012/11/16/opendkim-multiple_domains/
+ // 2) copy the private key in your ./local directory (/var/www/boutique/local/mail.default.private)
+ // 3) replace the full path and the domain name by the correct value here
+ private $useDkim = true;
+ private $dkimPrivateKeyPath = '/var/www/boutique/local/mail.default.private';
+ private $dkimDomainName = 'example.tld';
+ private $dkimSelector = 'default';
+ // }}} added by @asenar - DKIM patch
/**
* @var \Swift_Mailer
*/
@@ -215,7 +221,30 @@ class MailerFactory
$this->parser->assign('locale', $locale);
- $instance = \Swift_Message::newInstance();
+ // {{{ added by @asenar - DKIM patch
+ $instance = null;
+ if ($this->useDkim) {
+ try {
+ $privateKey = file_get_contents($this->dkimPrivateKeyPath);
+ $domainName = $this->dkimDomainName;
+ $selector = $this->dkimSelector;
+ $signer = new \Swift_Signers_DKIMSigner($privatekey, $domainName, $selector);
+
+ $instance = \Swift_SignedMessage::newInstance();
+ $instance->attachSigner($signer);
+ }
+ catch(Exception $e) {
+ // raise exception if dev mode only ?
+ //$instance = \Swift_Message::newInstance();
+ $instance = null;
+ }
+ }
+ if (!$instance) {
+ $instance = \Swift_Message::newInstance();
+ }
+ // This was
+ // $instance = \Swift_Message::newInstance();
+ // }}} added by @asenar - DKIM patch
// Add from addresses
foreach ($from as $address => $name) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.