Skip to content

Navigation Menu

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] Images in TemplatedEmail are sended as attachments instead of to be rendered using Async and Dkim Signer #50685

Copy link
Copy link
Open
@pavel-macovschi

Description

@pavel-macovschi
Issue body actions

Symfony version(s) affected

6.2.10

Description

When I send Templated Emails async all of the images that should be rendered are sended as attachments other parts of html template like buttons looks good.

How to reproduce

# Configuration
framework:
    messenger:
        transports:
            liip_imagine: '%env(MESSENGER_TRANSPORT_DSN)%/symfony/consumer-%env(CONSUMER_ID)%?auto_setup=true&delete_after_ack=true'
            async: '%env(MESSENGER_TRANSPORT_DSN)%/symfony/consumer-%env(CONSUMER_ID)%?auto_setup=true&delete_after_ack=true'
            sync: 'sync://'

        routing:
            Liip\ImagineBundle\Message\WarmupCache: liip_imagine
            Symfony\Component\Mailer\Messenger\SendEmailMessage: async


# Templated email
$email = new TemplatedEmail;
$email->templatedEmail
    ->from($fromEmail)
    ->to($toEmail)
    ->priority(Email::PRIORITY_HIGHEST)
    ->subject('Signup confirm')
    ->htmlTemplate('emails/signup_confirm.html.twig')
    ->context(['item' => $item])
;

# Render body before sending.
if ($email instanceof TemplatedEmail) {
    $this->bodyRenderer->render($email);
}

# Add a dkim_private key.
$privateDirectory = $this->getParameter->get('app.private_dir');
$domain = $this->getParameter->get('app.dkim.domain');
$path = $privateDirectory.'ssl'.DIRECTORY_SEPARATOR.'dkim_private.key';
$privateKey = file_get_contents($path);

# DKIM Signing.
$signer = new DkimSigner($privateKey, $domain,  'dkim');

# Sign email.
$signedEmail = $signer->sign($email);

# Dispatch email
try {
    $mailer->send($signedEmail);
} catch (TransportExceptionInterface $e) {
    $logger->critical($e->getMessage());
}

Possible Solution

After some tests with sending templated emails I have these results:

  1. When I disable Dkim signing and send using Async everything looks good. Images in templated email are rendered as other parts of templated email.
# Configuration
framework:
    messenger:
        transports:
            liip_imagine: '%env(MESSENGER_TRANSPORT_DSN)%/symfony/consumer-%env(CONSUMER_ID)%?auto_setup=true&delete_after_ack=true'
            async: '%env(MESSENGER_TRANSPORT_DSN)%/symfony/consumer-%env(CONSUMER_ID)%?auto_setup=true&delete_after_ack=true'
            sync: 'sync://'

        routing:
            Liip\ImagineBundle\Message\WarmupCache: liip_imagine
            Symfony\Component\Mailer\Messenger\SendEmailMessage: async


# Templated email
$email = new TemplatedEmail;
$email->templatedEmail
    ->from($fromEmail)
    ->to($toEmail)
    ->priority(Email::PRIORITY_HIGHEST)
    ->subject('Signup confirm')
    ->htmlTemplate('emails/signup_confirm.html.twig')
    ->context(['item' => $item])
;

# Render body before sending.
if ($email instanceof TemplatedEmail) {
    $this->bodyRenderer->render($email);
}

# Add a dkim_private key.
$privateDirectory = $this->getParameter->get('app.private_dir');
$domain = $this->getParameter->get('app.dkim.domain');
$path = $privateDirectory.'ssl'.DIRECTORY_SEPARATOR.'dkim_private.key';
$privateKey = file_get_contents($path);

# DKIM Signing disabled.
// $signer = new DkimSigner($privateKey, $domain,  'dkim');

# Sign email.
// $signedEmail = $signer->sign($email);

# Dispatch email without dkim signer.
try {
    $mailer->send($email);
} catch (TransportExceptionInterface $e) {
    $logger->critical($e->getMessage());
}
  1. When I keep dkim signing and disable Async templated email looks good and contains dkim signature but with a drawback on performance.
# Configuration
framework:
    messenger:
        transports:
            liip_imagine: '%env(MESSENGER_TRANSPORT_DSN)%/symfony/consumer-%env(CONSUMER_ID)%?auto_setup=true&delete_after_ack=true'
            async: '%env(MESSENGER_TRANSPORT_DSN)%/symfony/consumer-%env(CONSUMER_ID)%?auto_setup=true&delete_after_ack=true'
            sync: 'sync://'

        routing:
            Liip\ImagineBundle\Message\WarmupCache: liip_imagine
           # Disable async
            # Symfony\Component\Mailer\Messenger\SendEmailMessage: async


# Templated email
$email = new TemplatedEmail;
$email->templatedEmail
    ->from($fromEmail)
    ->to($toEmail)
    ->priority(Email::PRIORITY_HIGHEST)
    ->subject('Signup confirm')
    ->htmlTemplate('emails/signup_confirm.html.twig')
    ->context(['item' => $item])
;

# Render body before sending.
if ($email instanceof TemplatedEmail) {
    $this->bodyRenderer->render($email);
}

# Add a dkim_private key.
$privateDirectory = $this->getParameter->get('app.private_dir');
$domain = $this->getParameter->get('app.dkim.domain');
$path = $privateDirectory.'ssl'.DIRECTORY_SEPARATOR.'dkim_private.key';
$privateKey = file_get_contents($path);

# DKIM Signing.
$signer = new DkimSigner($privateKey, $domain,  'dkim');

# Sign email.
$signedEmail = $signer->sign($email);

# Dispatch email
try {
    $mailer->send($signedEmail);
} catch (TransportExceptionInterface $e) {
    $logger->critical($e->getMessage());
}

Additional Context

No response

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.