Files not being attached to the email

Created on 25 June 2025, about 1 month ago

Problem/Motivation

I am using webform module version 6.3.0 beta2. I am using sub-module Webform Attachment to attach files and a contributed module Webform Entity Print.

So on submission, webform sends an email to the admin with two attachments (uploaded file and submitted data as pdf file).

Now the submitted data as pdf is being attached in the email but not the uploaded file.

Should I go back to version 6.2.9?

What can I do to fix this issue.

Please help!

💬 Support request
Status

Active

Version

6.3

Component

Code

Created by

🇳🇱Netherlands a.kahn

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @a.kahn
  • 🇳🇱Netherlands Krilo_89

    We're having the same issue with 6.3.0-beta2.

    Files uploaded to the webform are not send as attachment through mail. The links towards the private files are inside the webform submission, but the users who receive those emails, don't have acces to private drupal files.

  • 🇧🇪Belgium bpironet

    Not sure if my issue is related but we had the same problem and rolled back to 6.2.9, but the issue was still there.

    After investigation, we understood that it was not related to Webform, but to Symfony Mailer due to this change: https://www.drupal.org/project/symfony_mailer/issues/3382624 📌 embedFromPath API addition (for #3284140) Needs work
    Now, private files are ignored in emails unless they are explicitly authorized by custom code.

    We created a custom EmailAdjuster plugin to allow private files to be attached to emails.

    
    namespace Drupal\your_module\Plugin\EmailAdjuster;
    
    use Drupal\Core\Access\AccessResult;
    use Drupal\symfony_mailer\EmailInterface;
    use Drupal\symfony_mailer\Processor\EmailAdjusterBase;
    
    /**
     * Defines the Attachment access Email Adjuster used for webform.
     *
     * @EmailAdjuster(
     *   id = "custom_webform_mailer_attachment_access",
     *   label = @Translation("Webform Attachment access"),
     *   description = @Translation("Grant basic attachment access to webform emails."),
     *   automatic = TRUE,
     *   weight = 100,
     * )
     */
    class WebformAttachmentAdjuster extends EmailAdjusterBase {
    
      /**
       * {@inheritdoc}
       */
      public function postRender(EmailInterface $email): void {
        // Loop through attachments and authorize those coming from form.
        foreach ($email->getAttachments() as $attachment) {
          if (...custom logic based on $email content...) {
            $attachment->setAccess(AccessResult::allowed());
          }
        }
      }
    
    }
    
    

    Regarding the custom logic to detect that the mail is from webform, you can add a custom header containing the webform_id via hook_mail_alter and try to detect it in the custom logic with: $email->getHeaders()->get('X-Drupal-Webform-ID')?->getBody();

    After that, the private attachments should be correctly included in your emails.

Production build 0.71.5 2024