Currently SWIFTMailSystem::mail is doing most of the formatting work, not SWIFTMailSystem::format. I think this is wrong. If you look at the interface description, you notice that mail() should just send the already formatted (and wrapped) message. It seems like HTML Mail and Mime Mail follows the interface more strictly.
The reason I'm raising this issue, is that at least on module - Views Send which I'm maintain - composes the message without sending it (calls drupal_mail() with $send parameter set to false). The messages are spooled and sent later from cron. This causes a problem since I need to handle the attachments specially since Swift Mailer are ignoring the attachments when calling format().
Please consider turning mail() into just a mail sending function.
PS! I guess this problem also is relevant for the D8 version.
Comments
Comment #2
sbrattla commentedAlthough
mail()does run your mail throughdrupal_alter('swiftmailer', $mailer, $m)which ultimately would allow other modules to directly manipulate the e-mail, it isn't doing much more than that. At least with respect to formatting.I'm not quite sure what you mean with
. Right now,
formatcreates a plain message of a HTML version (if applicable) and process any inline image attachments. Themailfunction mostly just puts the pieces together and instantiates aSwiftMailerrepresentation of the given mail - and ships it.Were you thinking of anything else in particular?
Comment #3
sbrattla commentedI didn't read the issue description well enough; I now see that it relates to attachments. Not formatting in the sense of formatting an e-mail's layout.
You'd like that
format()prepares the e-mail up to the point that it is "self contained". That is, is should also hold attachments. You then want to be able to serialize/deserialize emails and not worry about wether files are still available upon sending the email (which could happen a day or two after you scheduled it for sending).That would be possible; but would attachment size be an issue? Do you spool messages to the database? What if someone spools 10000 messages with a 1MB attachment? You'll suddenly require 10GB more of your database; that might be an issue on hosted websites.
What's your take on that?
Comment #4
hansfn commentedThx for reading the issue properly ;-)
The problem with spooling of large messages is real, but that isn't an excuse for violating the MailSystemInterface interface ;-) It's the problem of the user.
If my use case for the Views Send module and the behavior of the HTML Mail and Mime Mail modules isn't convincing, please enable the Mail System module and got to config/system/mailsystem. You'll notice that you can define a new class which uses different classes for formatting and sending. I could for example use MimeMailSystem for formatting and DevelMailLog for sending. It's actually very useful. The Swift Mailer module can't be used this way.
I understand that you might not want to rewrite the module, but please consider it. If you decide to not do it, please document that the module doesn't follow the MailSystemInterface interface properly.
Comment #5
hansfn commentedAny news related to this issue? Do you know if it is an issue for the D8 version too? (Sorry, didn't have time to test right now.)
Comment #6
hansfn commentedI have confirmed that this is an issue for D8 too. I suggest fixing it in D8 first and then do a backport to D7 if there are resources.
Comment #7
geek-merlinI folded the other issue into this for now so we can get consensus on the direction.
We might or might not re-separate this later.
Comment #8
geek-merlinComment #9
geek-merlinI dug through the views_send codebase and got a feeling for how it does things.
It's right that mimemail (which was D7 defacto standard) does things quite different to swiftmailer (which seems string in the D8 ecosystem).
But when using swiftmailer both for ->format() and ->send(), things should work out.
The problem i see in the current views_send codebase is that views_send_deliver() assumes all necessary information is in 5 items of $message and throws away the rest. That assumption should be simple to remove. Postponing until new insights on this.
Comment #10
geek-merlinAdded googlefood.
Comment #11
hansfn commentedIt don't think this issue should be about Views Send, but about breaking the API. I don't think every mail module should assume that it handles both formatting and sending. I can easily imagine one module being better at the formatting part, but maybe lacking some feature for the sending part. One example from D7 - Using HTML Mail together with SMTP Authentication Support Another example - D7 and D8: Using the DevelMailLog class to save the email as a file.
Anyway, if the "solution" is that you must use SwiftMailer for both sending and formatting, that should be properly documented.
PS! The Views Send code is crappy - I made a crappy D7 port and then a probably even worse D8 port. Anyway, what many people forget when they think Views Send is doing strange things, is that is supports spooling the message and sending them later using cron.
Comment #12
geek-merlin@hansfn: I'm really happy you chime in here! As swiftmailer maintainer i'm totally willing to put in some energy to improve the ecosystem of the most important main modules, and views_send is definitely on my radar.
I did not actively use views_send yet, but maybe i'll soon do and might suggest a patch for #10 (unless below!).
Currently we're doing a sprint on getting swiftmailer 2.x to beta. Unfortunately no one i know has bandwidth for this. But if you (or someone else) provides a patch for this issue before beta, i'd be more thant happy to review it!
Comment #13
geek-merlin> PS! The Views Send code is crappy - I made a crappy D7 port and then a probably even worse D8 port.
Yes i noticed that... But it's there and works for some.
> Anyway, what many people forget when they think Views Send is doing strange things, is that is supports spooling the message and sending them later using cron.
Did you notice that swiftmailer can handle the spooling part? This might be a chance to get an upcoming cleanup version of views_send more focused. ;-)
Comment #14
hansfn commentedI don't use SwiftMailer, so no patches coming from me. And Views Send should continue to work with other modules than SwiftMailer.
In other words, I give up. I'll make a clear notice in the Views Send documentation about using SwiftMailer for both formatting and sending.