hostbrook / laravel-dkim

Sign all outgoing emails in Laravel 9.x with a DKIM signature.
https://github.com/hostbrook/laravel-dkim
MIT License
0 stars 2 forks source link

error trying to send email #3

Closed bardolf69 closed 10 months ago

bardolf69 commented 1 year ago

I've just installed your package but I'm getting an error Unable to load DKIM private key: error:1E08010C:DECODER routines::unsupported {"exception":"[object] (Symfony\\Component\\Mime\\Exception\\InvalidArgumentException(code: 0): Unable to load DKIM private key: error:1E08010C:DECODER routines::unsupported at /app/vendor/symfony/mime/Crypto/DkimSigner.php:47), any ideas on what the problem may be?

I have double-checked and my config is exactly as you said in your docs.

'dkim_selector' => 'website',
    'dkim_domain' => '******.com',    
    'dkim_passphrase' => '',
    'dkim_private_key' => '-----BEGIN RSA PRIVATE KEY-----
    MIIEpQIBAAKCAQEA8Hbh9KEG0d5sfFIT/1ym2bphI5y/iK2+dz6Yf4nydqmTvCUJ
   ***omitted for security***
    f7jY+uvqTirSH3Plg4g8TT8+GMkVNBf3xiEJZhntFg45IfGhObE+vNI=
    -----END RSA PRIVATE KEY-----',
hostbrook commented 1 year ago

Good day, sorry for the delay in response. Can you please provide the following info:

  1. What version of Laravel do you use?
  2. Have completed step Nr. 2 (changes in config/app.php) ?
  3. Please check everything between two instances '-----BEGIN RSA PRIVATE KEY-----' and '-----END RSA PRIVATE KEY-----' must be right up to the start of the line. Please confirm this.
bardolf69 commented 1 year ago

Sorry, for the delay in my response I got stuck with other problems and DKIM support got pushed to the rear. I'm back on it again now.

  1. I'm running Laravel 10.30.1
  2. I'm not sure what the changes are because you already had Laravel 10 support when I installed the package.

added the following to config/app.php

HostBrook\LaravelDkim\DkimMailServiceProvider::class,

couldn't comment this line out as it doesn't exist

// Illuminate\Mail\MailServiceProvider::class,

here is the full list of my service providers

/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\HorizonServiceProvider::class,
App\Providers\RouteServiceProvider::class,
App\Providers\FortifyServiceProvider::class,
App\Providers\JetstreamServiceProvider::class,
App\Providers\ViewServiceProvider::class,
HostBrook\LaravelDkim\DkimMailServiceProvider::class

You can see my config/mail.php settings in my original post.

  1. I have tried the private key both with the start and end tags and without. Also both in the block format they normally come in and a single line without linebreaks. none of those 4 methods made any difference.
bardolf69 commented 1 year ago

originally I was using a keypair generated by the Socketlabs tool that you list in your docs, I then tried generating it a second time in the same tool. Finally I generated the keypair myself with openssl using the following commands.

openssl genrsa -out dkim_private.pem 2048
openssl rsa -in dkim_private.pem -pubout -outform der 2> nul | openssl base64 -A
bardolf69 commented 12 months ago

any thoughts?

hostbrook commented 12 months ago

checking...

hostbrook commented 12 months ago

Ok, I have completed tests on two projects. One was recently upgraded from Laravel 9.x to 10.31.0, and another one was made from scratch on Laravel 10.30.0. Both work perfectly with the package. You can test it by yourself if fill out the "Contact Us" form at the website hostbrook.com and put your email in the form. You will receive a confirmation email, so check just the headers, should be something like this:

Authentication-Results: spf=pass (sender IP is 198.71.225.122)
 smtp.mailfrom=hostbrook.com; dkim=pass (signature was verified)
 header.d=hostbrook.com;dmarc=pass action=none
 header.from=hostbrook.com;compauth=pass reason=100
Received-SPF: Pass (protection.outlook.com: domain of hostbrook.com designates

Also, another contributor confirmed this package works without errors on his side. Moreover, there were not any changes for the mailer between Laravel 9.x and Laravel 10.x versions.

I would suggest checking in composer.json file the version of package, for Laravel 10.x it should be:

"hostbrook/laravel-dkim": "^1.2.5"

And again, the most often issue I met is hidden symbols at the beginning of lines between two instances '-----BEGIN RSA PRIVATE KEY-----' and '-----END RSA PRIVATE KEY-----'. They must be right up to the start of the line. Be sure at the end of the line no hidden symbols (like TAB). This is a copy from hostbrook.com config:

    'dkim_selector' => 'selector1',
    'dkim_domain' => 'hostbrook.com',
    'dkim_passphrase' => '', // leave empty if you didn’t protect the private key
    'dkim_private_key' => '-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAq1SCAScdt736Rr/f36OYUo8cRziq4v2uq6kNs5wzEaaqUAoh
SKGzonNp6Pis4AalVId633E/9QLnnxfA19Ne7tIewfK9Wug91iY16+3r9CTSGCTT
...
u4DsesAgyr1uJ6jhEPfgAbRxWfiJ0dQ6RtTXJAxYZZOuH8h2XdGqsfrk5D6WuopP
ENwDlqtgpM9D7YdnrL6W9NH7fdSwmz2Ux0frY6weuBx/VSeJn1fb
-----END RSA PRIVATE KEY-----',

To be honest, I do not know what else you can check. It is a very simple package and it works perfectly on at least 3 projects I have checked today.

hostbrook commented 12 months ago

You know what, try one more step to publish the config file; in the terminal:

php artisan vendor:publish --provider="HostBrook\LaravelDkim\DkimMailServiceProvider"

please let me know the status. Also, in the next version I'm planning to add the option to load the private key from the txt file. Maybe this will work for you.