Closed (works as designed)
Project:
Mime Mail
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
9 Mar 2018 at 08:31 UTC
Updated:
22 Jun 2020 at 08:59 UTC
Jump to comment: Most recent
Comments
Comment #2
tr commentedComment #3
tr commentedActually, Mime Mail already supports this. See the mimemail_example module which uses file_save_upload() to attach files.
Comment #4
hansfn commentedI think you missed the fine point of my feature request - handle file entities directly.
It seems counter-productive to (manually) convert file entities to file objects / arrays when Drupal core uses file entities internally. I thought file objects was the Drupal 7 way and file entities the Drupal 8 way.
For the record: It's not only Mime Mail that is stuck in Drupal 7 land when it comes to attachments. I think Swiftmailer have the same problem. Excerpt from a (random) blog post (using Swiftmailer):
Comment #5
tr commentedI think Mime Mail is already handling file entities directly. I have been writing documentation (not yet published) to show the various ways to attach files to email, and one way is to directly use a public://, private://, or a temporary:// URL to attach a file entity. This works.
Try this on your own website - you can add this code to mimemail_example:
That video.png file is available as a file entity on any Drupal site that has the Media module enabled. Or if you have the file entity as a variable $file, then use
'filepath' => $file->getFileUri(),. This is just the same as passing around a node ID to refer to the node entity. We are definitely NOT passing around the file entity contents, just the unique entity URL.Likewise, what I said above - I use file_save_data() to upload data into a file entity on the website OR to dynamically create file entities on the website for attaching.
I think the confusion come because the $attachments parameter accepted by mimeMailHtmlBody() is an array - but it's an array of *metadata* about the attachment - it's not the attachment itself. In the case of a file entity, the metadata just contains the URL of the file entity, it does not contain the actual data. Again, this is like passing around a node ID.
We don't want to JUST accept a file entity type $attachments parameter because we have other use cases than just file entities - dynamically-created text or image content, for example, where we DON'T want to create a file entity, we just want to attach the data. We need to support more than one use case.
But we do handle file entities directly with that thin metadata wrapper, along with the other use cases, so I think the status of this issue is correct - that already works.
Yes, there still a lot of ugliness in the code and a lot of leftover D5, D6 and D7 stuff, but that's what I've been working hard at eliminating over the past two months. 55 commits over the past two months, including making this module D9 compatible and making the first release in more than 3 years. I've added testing, and in the process found and fixed serious bugs, I've ported the missing submodule mimemail_example, I've written the documentation, etc. I have read through old issues, like this one, and considered them. I am not just closing things because they're old, I'm dealing with each issue on its merits.
There's still a lot of things that either don't work or haven't been shown to work properly. I'm addressing each of those as I find them. You can help by participating in the issue queue: reviewing or posting patches, answering support questions, improving the documentation, etc. I can't continue to put in this much effort on a volunteer basis without community participation, so if this module is important to you please help.
Comment #6
hansfn commentedOK, I guess I was considering the file entity as the base / most used case and hence wanted that to be super smooth to use. I'm fine with the current situation - it was just a feature request, not a bug report.
PS! If I had time, I would have helped out. I barely have time to make Views Send work. It's a struggle when the different (Mime) mail modules don't use the same setup for attachments, they don't follow the mail interface (format VS mail) and so on. And I never had time to rewrite the module properly for Drupal 8.