HTML mail actions for Rules
jpetso - June 25, 2009 - 07:54
| Project: | Mime Mail |
| Version: | HEAD |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
| Issue tags: | HTML email, mimemail, rules integration, tokens |
Description
Yesterday I felt like "whatever, I'm not going to be productive today anymore so let's create some Rules actions for Mime Mail instead", and alas, attached to this issue you can find those. Straight port of Rules' own text mail actions with a few Mime Mail specific extras, so the copyright for these files is with me and fago.
| Attachment | Size |
|---|---|
| mimemail-rules.diff | 8.28 KB |

#1
Awesome, this rocks! Sending HTML mails with rules is highly required. Many thanks! Have I already said that we'll miss you Jakob? ;)
Will test it and report back...
#2
Patch applied nicely. Tested functionality with a custom rule: HTML mail got sent out as expected, attachements are working great too. :)
#3
Small addon: Inserting tokens and php variables is not working with this patch...
#4
I feared this would be the case, with the storage not being simple strings anymore. I might go researching how Rules accomplishes this, and whether it's necessary to go back to string storage instead of prepared arrays.
#5
oh nice, this feature was already often requested by rules-users.
@input evaluators: I think you simply forgot to add some settings to the 'input eval' properties, e.g. 'message_html' is not in there.
Also I'd suggest to the doxygen
* @addtogroup rules* @{
in the beginning and
/*** @}
*/
in the end. So the functions appear in the rules integration docgroup.
#6
ah, and does mimemail remove "\r" and "\n"? As the patch does it only on configuration time, but this wouldn't apply to tokens.
#7
To fix the token issue mentioned above and implement fago's suggestion and doxygen marks, try this additional path (on top of the one above).
It tells rules to evaluate the message_html and message_plaintext variables to replace tokens. It adds doxygen marks (hope I did it right).
With these changes, HTML email works, tokens get replaced!
#8
(separating tags by commas, not spaces)
#9
Sorry for this noob question - but what file is this patching is this a new file to go in the rules module - module directory called mimemail.rules.inc. (Because I dont have this file in rules or mimemail module)
What am I missing I understand comment #7's adjustment to the initial attachment just dont know what the original file is patching.
Any basic instructions appreciated
#10
@StephenFresh
The original patch is adding new files to the mimemail module. Just run it in the mimemail module root directory. Patch in #7 is only adressing changes for fixing the token issue...
#11
Thanks Criz for the help did that and it created the two extra files - added those to the module and it appears to work.
Though i hit another issue I'm running a patched version of smtp ( http://drupal.org/node/132903 ) to work with mimemail which works well btw.
The problem is I get this error when triggering the html email sending rule (Send an HTML mail to an arbitrary mail address) in question:
"The submitted from address () is not valid."
normal from email address prompts this error also left blank to use the sites email prompts the same error
Any tips on adjusting the above patch/es so that the from address is being passed to smtp module correctly?
#12
The patch from #7 is not working with recipients. Code in mimemail_rules_action_mail_submit() is responsible for that. Don't know if mimemail is removing "\r" and "\n", seems not.
Successfully added support for cc and bcc recipients btw. If this above mentioned problem is solved I will post a patch...
#13
ah, sry I've missed something. The token replacements only work as long as the setting stays as "string", thus transforming it into an array has to happen at action runtime - after the token evaluation.
#14
so, here is a full patch with working token and php variables and cc/bcc recipient fields for the "send mail to an arbitrary mail address" actions...
#15
I tried this patch #14 - but i still get same problem - as #11 - I'm sure it would work if i didnt have smtp in the process and there in lies my problem.
#16
I tried this patch #14, and... thank you very mutch !
I would just notice that, (maybe it's only for my case) php is well interpretated in the recipient address field, but not in body.
Then, it seems that it doesn't use the same template than the original 'sent mail to an arbitrary e-mail adress' because using the same code, I get a buggy mail...
But guys, if you didn't post these patches, i would have been in the mess... So A big Thanks to you !
#17
@seren10pity
What exactly is buggy in the mail?
Php is working great for me in mail body, but have tested it only with "send mail to an arbitrary e-mail adress" action.
But I've noticed some issues with php in bc and bcc fields...
#18
@mimemail_rules_action_mail_to_user_submit:
As I said in #14 this processing of strings needs to happen on-execution time as then the tokens/input evaluators got applied! Once they have been applied on the strings, you can process them.
#19
Okay, here is the patch from #14 with some changes:
-- string validation only on execution time
-- some further small improvements suggested by fago
Tested it heavy on 2 different Drupal Installations and it works fine. Also tested and validated with coder module...
#20
It works very well.
How can we customise the default presentation?
#21
I did another code-review:
* imho $settings['bc'] should be $settings['bcc'] - why bc!?!?
* settings validation: Imho the function is misnamed, currently it does setting processing but this is no validation and is quickly confused with form validation.
+ //if $user is empty set acting user
+ if (empty($user)) {
+ global $user;
+ }
This is quite confusing as never mail is going to be sent to the active user that way. I think it woould make more sense to leave $user unset when we are sending to $settings['to']. But that's probably minor.
#22
Thanks for this very useful module and patch. I've been testing the HTML email formatting.
There is also a problem when when using
<a href="mailto...">in the HTML body of an email send from Rules in HTML markup. Spaces are added to the HTML markup which can break<A>links in the text. It seems to be a bug but I don't know where.Example Body:
<a href="mailto:test@tutttestmail.com?subject=Subject's Text&body=Dear User%0AIt's good to here from you.>send email</a>Where %0A is HEX for a new line, but this does not work in the resultant email text. No new line is added. When I view the source markup in the email client (outlook) %0A is replaced with a new line but it needs to remain %0A in the source for the mailto to have a newline in the resultant email. I am not sure if this is a mail client issue - its seems not since the source markup has a new line thus it received the source without the %0A. The source email is recieved with %20 which is the HEX for spaces ' '.
ALSO, When using an apostrophe, as in ', in the text or title a / is added before the apostrophe (/') in the subject and body of the sent email text.
ALSO, found issue with using multiple
for some reason they have spaces added to them. I am not sure is this is due to the same issue mentioned a few lines above.#23
great work jpetso, criz, & fago - I'm looking forward to testing this out ;)
#24
Thanks for these useful rules.
I have problems with token replacements. They work with normal "system email" but not with mimemail rules (the list of replacement available appear as normal but the email just show the [not replaced]).
I use the last dev of token module and last rules module, and I have applied patch 19.
Any help would be appreciated (question for the other users : did you make it work with token replacements?).
Thanks!
Tomski
#25
Hi, did you use the patch from #19? Which rules action did you use?
criz
#26
That was a very quick answer! In fact it was patch 19 (I have just edited the comment #24).I have tried both "to arbitrary address" and to "user " with no success.
Since I was not sure about which patch I have applied I re-applied and re-install it on the drupal site. The old action still does not work even after updating it, but any new action created now it works. Sorry about having posted an issue without double-checking before if I had gone through all the suggested steps to solve the problem (I am quite sure it was the patch #19 but not 100% since I have applied more than one week ago).
Thanks in any case!
Tomski
#27
Hmmm, I've not tested this with current token dev and rules 1.1 so far. Does it work with a standard rules action? Do php variables work?
Maybe you face a simular issue to http://drupal.org/node/432518
Okay, so it works now. Great... :)
#28
this was pretty much working great for me except for one thing.. in the plaintext version of multipart emails all of my carriage returns are getting stripped out
i notice on line 135 of mimemail.rules.inc
$settings['message_plaintext'] = str_replace(array("\r", "\n"), '', $settings['message_plaintext']);when i comment this out of course my carriage returns come back.. but i'm no expert at php and am not sure if its a problem to drop this line
thanks for this integration with rules!
#29
This works well when insreting html in the message box in Rules
However, token replacement of HTML content only displays the corresponding HTML code, but does not not render it.
(in other words, if the node content is plain text, it works OK, but if it is rich HTML text, that does not work...)
#30
After a recent core upgrade (6.12 -> 6.14) I now see this error editing existing page "Send an HTML mail to an arbitrary mail address":
warning: preg_match() expects parameter 2 to be string, array given in /var/www/.../includes/bootstrap.inc on line 777.Should this be anything to worry about? What are the implications?
#31
jvieille, do you have used the raw tokens? Just wondering, because rendering html token works for me...