Skip to content

Instantly share code, notes, and snippets.

@yebt
Last active June 20, 2023 21:46

Revisions

  1. yebt revised this gist Jun 20, 2023. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion private_key.txt
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    # storage/app/dkim/private_key.txt
    #here write the private key generated from the dkim support on your host
    #or from this great tool: https://tools.socketlabs.com/dkim/generator
    # in the host manage go to cpanel zone editor and search dkim._domainkey.you_domain.com or default._domainkey.you_domain.com
    # in the host manage go to cpanel zone editor and search dkim._domainkey.you_domain.com or default._domainkey.you_domain.com
    # CPANEL
    # Email Deliverability > [press "Manage" button of select domain] > see the dkim menu
  2. yebt revised this gist Jun 20, 2023. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions private_key.txt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    # app/dkim/private_key.txt
    # storage/app/dkim/private_key.txt
    #here write the private key generated from the dkim support on your host
    #or from this great tool: https://tools.socketlabs.com/dkim/generator
    #or from this great tool: https://tools.socketlabs.com/dkim/generator
    # in the host manage go to cpanel zone editor and search dkim._domainkey.you_domain.com or default._domainkey.you_domain.com
  3. yebt revised this gist Nov 1, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion GeneralMail.php
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ class GeneralMail extends Mailable{
    #...
    public function build()
    {
    $this->subject(__('Reset Password'))
    $this->subject(__('General Mail'))
    ->view('mails.resetpassword')
    ->text('mails.resetpassword_plain');
    add_dkim_to_mailable($this); // this call the helper
  4. yebt created this gist Nov 1, 2022.
    17 changes: 17 additions & 0 deletions GeneralMail.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    <?php

    #...
    # app/Mail/ResetPassword.php
    #...

    class GeneralMail extends Mailable{
    #...
    public function build()
    {
    $this->subject(__('Reset Password'))
    ->view('mails.resetpassword')
    ->text('mails.resetpassword_plain');
    add_dkim_to_mailable($this); // this call the helper
    return $this;
    }
    }
    29 changes: 29 additions & 0 deletions Helper.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    <?php
    #-...
    # app/Helpers/Helper.php

    if (!function_exists('add_dkim_to_mailable')) {
    /**
    * This function add a Dim sign to mailable entities.
    * @param Mailable $mailable the mailable entity
    * @return void
    */
    function add_dkim_to_mailable(Illuminate\Mail\Mailable $mailable)
    {
    $mailable->withSwiftMessage(function (\Swift_Message $message) {
    // DKIM INFO
    $dkim_privatekey = config('manualdkim.private_key');
    $dkim_selector = config('manualdkim.selector');
    $dkim_domain = config('manualdkim.domain');
    if (
    empty($dkim_privatekey) &&
    (!file_exists($dkim_privatekey) &&
    (empty($dkim_selector) && empty($dkim_domain)))
    ) {
    return;
    }
    $signer = new \Swift_Signers_DKIMSigner(file_get_contents($dkim_privatekey), $dkim_domain, $dkim_selector);
    $message->attachSigner($signer);
    });
    }
    }
    9 changes: 9 additions & 0 deletions dkim.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    <?php

    # this file is in `config/manualdkim.php`

    return [
    'private_key' => env('DKIM_PRIVATE_KEY', storage_path('app/dkim/private_key.txt')),
    'selector' => env('DKIM_SELECTOR', 'default'),
    'domain' => env('DKIM_DOMAIN', null),
    ];
    3 changes: 3 additions & 0 deletions private_key.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    # app/dkim/private_key.txt
    #here write the private key generated from the dkim support on your host
    #or from this great tool: https://tools.socketlabs.com/dkim/generator