Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending images as inline attachments? #74

Open
mpdude opened this issue Apr 23, 2021 · 1 comment
Open

Sending images as inline attachments? #74

mpdude opened this issue Apr 23, 2021 · 1 comment

Comments

@mpdude
Copy link

mpdude commented Apr 23, 2021

When sending emails (after all, that's what MJML is all about) that contain images, it is often helpful or even necessary to attach images to the emails – that way, you can ensure emails are rendered correctly, without blocking access to "external" resources in the mail client.

I understand that this currently out of scope for this bundle, since all it does it to provide a way to apply the MJML -> HTML transformation for Twig templates, and also the existing integration/plugin/support for SwiftMailer has been deprecated.

However, the problem seems to be closely related to MJML processing and the use case should make sense for most of the people using this bundle.

The downside is that supporting it would mean that not only the MJML/HTML would have to be processed, but also some kind of integration with the mailer system used (SwiftMailer, Symfony Mailer, ...?) would be necessary to support attachments to the messages.

What do you think – would you be open for proposals or contributions in this regard, and have you (as the maintainer) faced this problem before?

@aprat84
Copy link

aprat84 commented Oct 2, 2024

AFAIK, mjml respects whats in the src attribute. So, as you said, I think this is out of mjml scope.

If you use the symfony/mailer component, according to the docs it should be easy to do!

If you use the symfony framework:

$email = (new TemplatedEmail())
    // ...
    ->htmlTemplate('emails/signup.html.twig')
<!-- emails/signup.html.twig -->
<img src="{{ email.image('@images/logo.png') }}" alt="Logo">

If you use the component standalone:

$email = (new Email())
$email->addPart((new DataPart(new File('/path/to/images/signature.png'), 'signature', 'image/png'))->asInline());
$email->html($twig->render('path/to/email.html.twig'));
<!-- path/to/email.html.twig -->
<img src="cid:signature" alt="signature">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants