[META] Attachments support

Created on 1 February 2022, almost 3 years ago
Updated 24 July 2023, over 1 year ago

Problem/Motivation

Symfony mailer supports embedding images and file attachements (https://symfony.com/doc/5.4/mailer.html#embedding-images / https://symfony.com/doc/5.4/mailer.html#file-attachments). At the moment this has not yet been implemented (as noted in https://www.drupal.org/docs/contributed-modules/symfony-mailer-0/feature β†’ ...), and the related methods are commented in Drupal\symfony_mailer\BaseEmailTrait.

Proposed resolution

Interface:

  1. YES attachFromPath(). Following Drupal conventions, probably the parameter should be called mime type instead of content type and if blank we should use the Drupal MimeTypeGuesser.
  2. YES embedFromPath() however we probably want the function to take care of assigning cid else every caller has to. Maybe it could be the same function as attachFromPath() - in the embed case the cid is used, in the attach case it is not (is there any other difference??)
  3. YES attachFile() from patch 15 which is a simple wrapper round the above
  4. NOT attach() or embed() because is loses the source of the file, which we most likely want for security checking
  5. PROBABLY NOT attachPart() as it doesn't seem to relevant to Drupal
  6. PROBABLY NOT getAttachments() not sure of the use case, because there is no way to modify them

Here are some ideas for how we might use attachments:

  1. Field formatter that adds a file as an attachment, for example for simplenews newsletter
  2. Email adjuster to attach a file which could be from a URL or an existing Drupal managed file or a UI ("browse" button) to upload a new file
  3. ✨ Email adjuster to attach/embed by scanning the email body Needs work
  4. Allow embedding images in BodyEmailAdjuster (possibly supporting the Twig syntax provided by Symfony)
  5. ✨ Add support to attachments for LegacyEmailBuilder Fixed

We need to consider security to control attaching of protected files. For Drupal managed files we could perhaps automatically check if the recipient has access to the file. However sometimes the admin might wish to override this - "yes the file is not public, but I am choosing to send it to this set of recipients".

We should check the webform module because it has similar features to some of these.

Original issue

The OP requested to implement direct support for the symfony mailer functions below. As maintainer, I propose that we start from the requirement discussion above and see what API it leads to.

  • attach()
  • attachFromPath()
  • embed()
  • embedFromPath()
  • attachPart()
  • getAttachments()

Remaining tasks

User interface changes

API changes

Data model changes

🌱 Plan
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany hchonov πŸ‡ͺπŸ‡ΊπŸ‡©πŸ‡ͺπŸ‡§πŸ‡¬

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024