Problem/Motivation
SMTPMailSystem has a fallback for attachment MIME parts where the attachment body is embedded in the formatted email instead of pointing to an existing filepath.
In that branch, SMTP decodes the attachment content, writes it to temporary:// with file.repository->writeData(), and then resolves the real filesystem path before adding
it to PHPMailer.
writeData() returns a Drupal file entity. The current code uses:
$file_path->uri
But on Drupal 10/11, uri is an entity field, not the raw URI string. Passing that field object to FileSystemInterface::realpath() is invalid/unreliable.
The correct API is:
$file_path->getFileUri()
Without this change, generated in-memory attachments can fail to be added to SMTP emails. One practical case is an .ics calendar invite generated by a mail formatter: the
invite is encoded into the MIME body, SMTP decodes it, writes it to a temporary file, then fails to resolve the temporary file URI correctly.
Steps to reproduce
1. Configure Drupal to send mail through the SMTP module.
2. Send a multipart email that contains an attachment MIME part, but does not provide the attachment through $message['params']['attachments'].
3. Use an attachment generated from content, for example an .ics calendar invite.
4. SMTP decodes the MIME part and writes it to a temporary file.
5. The attachment is not added correctly because the code passes $file_path->uri to realpath().
Proposed resolution
Use the file entity API method getFileUri() instead of reading the uri field property directly:
- $real_path = $this->fileSystem->realpath($file_path->uri);
+ $real_path = $this->fileSystem->realpath($file_path->getFileUri());
Why This Is Needed
This uses the public FileInterface API and returns the expected URI string, e.g. temporary://smtp..., allowing FileSystemInterface::realpath() to resolve the temporary file
correctly and PHPMailer to attach it.
Issue fork smtp-3619941
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
gooddenis commented