Skip to content

Issue #3462662: Add possibility to attach PDF files to the e-mail

  • Adds a new "attachments" single value string field to the Email entity
  • this stores a file field name in the target entity. The attachment file itself is problematic due to file has an ID, and Email is a configuration and those could not be in sync, so it was easier to build a solution where we reference to fields for which files to send in the Email.
  • this way, EmailSender can load all the files in the target entity and attach them in a format Symfony Mailer uses
  • common use case could be generating dynamically an invoice PDF to an order file field and that could be set this way for sending
  • another special use case in a code: if the target entity is a commerce_order, then file fields from commerce_store also could be set for an Email. This way, usual PDF documents such as "terms and conditions" or "return policy" can be uploaded to a store field and using that field, those files could be attached to Emails
  • I defined 2 events in the MR:
    1. MailAttachmentAlterEvent: this is aimed for external modules, they can alter which files are attached to Emails
    2. MailAttachmentListAlterEvent: right now in the MR, on the Email form the Attachments field lists available file fields in the target entity. But with this event we give a possibility for developers to add their own options for attachment settings. So they can write code that add files in a MailAttachmentAlterEvent only when the Attachments field is set to their own value. For example they define a new option called "User manual in product" with MailAttachmentListAlterEvent subscriber. And they write an own subscriber to MailAttachmentAlterEvent that attach product manuals to the Email only if the "User manual in product" was set for an Attachments option in the Email entity.

Merge request reports