You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
I keep getting a DkimSigner error. "Unable to load DKIM private key"
I have added various debugs to check that the private key is readable
and I created the key directly on the server with:
openssl genpkey -algorithm RSA -out priv_key.pem
I assume I must have got something wrong even though my debugs are not showing it.
This is the full error:
Fatal error: Uncaught Symfony\Component\Mime\Exception\InvalidArgumentException: Unable to load DKIM private key: error:0909006C:PEM routines:get_name:no start line in /home/aiaugdju/prod.aiauto.cloud/main2/app_main/vendor/symfony/mime/Crypto/DkimSigner.php:47
I'm running PHP 8.1
I am trying to move from SendinBlue to use Symfony
and this is my composer.json
{
"name": "kekek/devenilu",
"description": "A simple deamon for collecting data from a central server, Csv",
"type": "project",
"require": {
"symfony/mailer": "^6.3",
"ext-pdo": "*",
"sendinblue/api-v3-sdk": "^8.4",
"ezyang/htmlpurifier": "^4.14"
},
"autoload": {
"psr-4": {
"App\\": "",
"App\\Core\\": "core",
"tests\\": "tests"
}
},
"minimum-stability": "stable"
}
Here is my code:
<?php
namespace App;
use GuzzleHttp\Client;
use SendinBlue\Client\Api\ContactsApi;
use SendinBlue\Client\Api\TransactionalEmailsApi;
use SendinBlue\Client\Model\SendSmtpEmail;
use SendinBlue\Client\Model\SendSmtpEmailAttachment;
use SendinBlue\Client\Model\SendSmtpEmailAttachmentUrl;
use SendinBlue\Client\Configuration;
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mime\Crypto\DkimSigner;
use Symfony\Component\Mime\Email;
class IMailer
{
/**
* @param $recipient
* @param $subject
* @param $html_body :
* @param $attachment_path
* @return void
* @throws TransportExceptionInterface
*/
public static function sendEmail($subject,$to_mail,$to_name,$htmlContent,$attachment,$newData)
{
.... other code for attachments
// DKIM private key path and selector
$dkimPrivateKeyPath = 'priv_key.pem';
$dkimSelector = 'nc-aiauto';
$dkimDomain = 'aiauto.cloud';
if (!file_exists($dkimPrivateKeyPath)) {
die("DKIM private key file not found.");
}
// Setup the SMTP transport
// The DSN format for SMTP connections should follow the pattern: smtp://username:password@host:port.
$transport = Transport::fromDsn("smtp://$smtpUsername:" . urlencode($smtpPassword) . "@$smtpHost:$smtpPort");
// Create the Mailer
$mailer = new Mailer($transport);
// Compose the email
$email = (new Email())
->from($smtpUsername)
->to($to_mail)
->subject($subject)
->html($htmlContent);
// Create a new Attachment instance
if ($attachment !== 'N' ){
foreach ($attachments as $attachment) {
$email->attachFromPath($attachment['url'], $attachment['name']);
}
}
try {
// Sign the email with DKIM
// Output the contents of the private.pem file
$privateKeyContent = file_get_contents($dkimPrivateKeyPath);
echo "Private Key Contents:\n";
echo $privateKeyContent;
$privateKey = openssl_pkey_get_private(file_get_contents($dkimPrivateKeyPath));
if (!$privateKey) {
die("Unable to load DKIM private key.");
} else {
echo "LOADED Private Key\n";
}
$signer = new DkimSigner($dkimPrivateKeyPath, $dkimDomain, $dkimSelector );
$signedEmail = $signer->sign($email);
// Send the email...
$mailer->send($signedEmail);
file_put_contents("processError.log", 'SendEmail-02 SENT EMAIL To: ' .$to_mail. "\n", FILE_APPEND); // FLAG SendEmail-02
return true;
} catch (TransportExceptionInterface $e) {
// Handle transport exceptions...
$errorMessage = "SendEmail-03 Error sending email: " . $e->getMessage();
file_put_contents("processError.log", $errorMessage . "\n", FILE_APPEND); // FLAG SendEmail-03
return false;
}
}
Add a bulleted list, <Ctrl+Shift+8>Add a numbered list, <Ctrl+Shift+7>Add a task list, <Ctrl+Shift+l>
Directly mention a user or teamReference an issue or pull request
Add heading textAdd bold text, <Ctrl+b>Add italic text, <Ctrl+i>Add a bulleted list, <Ctrl+Shift+8>Add a numbered list, <Ctrl+Shift+7>Add a task list, <Ctrl+Shift+l>
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
{{title}}
-
Hi everyone.
Hope you are keeping well !!
I keep getting a DkimSigner error. "Unable to load DKIM private key"
I have added various debugs to check that the private key is readable
and I created the key directly on the server with:
openssl genpkey -algorithm RSA -out priv_key.pem
I assume I must have got something wrong even though my debugs are not showing it.
This is the full error:
Fatal error: Uncaught Symfony\Component\Mime\Exception\InvalidArgumentException: Unable to load DKIM private key: error:0909006C:PEM routines:get_name:no start line in /home/aiaugdju/prod.aiauto.cloud/main2/app_main/vendor/symfony/mime/Crypto/DkimSigner.php:47
I'm running PHP 8.1
I am trying to move from SendinBlue to use Symfony
and this is my composer.json
Here is my code:
The debug output is :
./cron.sh
Private Key Contents:
-----BEGIN PRIVATE KEY-----
MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAOZ4fCHFMj5N/a4/
WDB4EuwogXKTSiZ00grXVkLKkU7tlMZMPhHQIz20c0p+PTZOJM9vde4uWujfw/tX
Nj/L2/GNyLK7ysOxOO8Mm4QD9UC5kU5qopI6Z12Xs3nfn9GJpoC866FBIdnzgVZu
KUzFdKX3i7/r89hAkVz7UbH9DgInAgMBAAECgYAv8UZZPA08mrq3waOVyZSeHbr3
253kLA75hFwEXuElWxTEv112FScPkfcduu7+2ficUiJlHq14nfvF0BmP4ddpni8u
JYKWwtM8LQ5kuiynbDNxTHmqYKjpnIROvSD79oIdrraW7sBFj2eEe86XRpoNxcYV
KBpZuVkeHfDfsVFXGQJBAPkDCqC3wvqqshaF8inFmmkNP3xxabRTofheHFtLDVL3
ynUulkpS+kcCP1fsRTHe1QLFtbvsLExGvQYjRdIKTYMCQQDs8D0m/ANyaROWgzMW
iAa9+aL1bBYYsKLwqY+W7S97nWn4Q9Z0Wo6iWtnO6xS8ejlwosHexKgJC0v7SMsu
UZuNAkBPV6rBPww/drg7+P4KVU43/uKlsjVuId/QFZyPckCSmSXHZMq6b+oTSiII
z93UYB4bPggEEuKigz+jfwW2QVYlAkEAlghuALCWEi19TNKZWAwckNFxogymVU4M
b24/UWexqIn+H0n9k0IAjcgPodn0EIEovC0jrEdEzC1OGLl4h0T/xQJAXvM4FJiX
MbI6BNsHj+75UU+Tn4nRIz/2SRCeq7+hYeo0QkAgWQCiwNCWVScxX8wzOpT6c+FB
+4zyOXSzEZ0g8w==
-----END PRIVATE KEY-----
LOADED Private Key
Fatal error: Uncaught Symfony\Component\Mime\Exception\InvalidArgumentException: Unable to load DKIM private key: error:0909006C:PEM routines:get_name:no start line in /home/aiaugdju/prod.aiauto.cloud/main2/app_main/vendor/symfony/mime/Crypto/DkimSigner.php:47
So, it seems that openssl_pkey_get_private() can read the private key file but DkimSigner() can not.
As you can see, I moved the private key right into the work directory
in order to make the path easy ( of course, normally it would be elsewhere )
Please let me know what I can do to get this working.
Many thanks.
Dave
Beta Was this translation helpful? Give feedback.
All reactions