Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[MAILER] DKIM signing not properly working with text part ? #40131

Copy link
Copy link
Closed
@geoffrey-brier

Description

@geoffrey-brier
Issue body actions

Symfony version(s) affected: At least 5.2.3

Description
I am trying to send emails and sign them using the DkimSigner but for some reason, when I add a text() part, Gmail cannot check the signature and I end up with the following error : dkim=neutral (body hash did not verify) .

How to reproduce
Here is how I create the Email.

    public function email(string $subject, string $from, $to, string $body, string $contentType = 'text/html'): Email
    {
        $email = (new Email())
            ->subject($subject)
            ->from($from)
            ->to($to)
        ;

        if ('text/html' === $contentType) {
            $email->html($body);
            // If I uncomment this, DKIM signature check fails
            // $email->text($this->htmlToText($body));
        } else {
            $email->text($body);
        }

        return $email;
    }

Here is the method that signs and sends the email (pretty straightforward).

    public function send(Email $email): bool
    {
        try {
            $privateKeyPath = __DIR__.'/../../dkim.pkey';

            if (file_exists($privateKeyPath)) {
                $signer = new DkimSigner('file://'.$privateKeyPath, 'mydomain.com', 'mydkimselector');

                $email = $signer->sign($email);
            }

            $this->mailer->send($email);
        } catch (\Exception $e) {
            return false;
        }

        return true;
    }

Additional context
I have added 2 mails which I received : one which passes and the other one which doesn't.

dkim-fail.txt
dkim-pass.txt

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.