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.

AttachmentSize
mimemail-rules.diff8.28 KB

#1

criz - June 25, 2009 - 14:17

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

criz - June 25, 2009 - 16:45

Patch applied nicely. Tested functionality with a custom rule: HTML mail got sent out as expected, attachements are working great too. :)

#3

criz - June 26, 2009 - 15:32

Small addon: Inserting tokens and php variables is not working with this patch...

#4

jpetso - June 26, 2009 - 15:44
Status:needs review» needs work

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

fago - June 27, 2009 - 11:53

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

fago - June 27, 2009 - 11:56

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

aantonop - June 29, 2009 - 19:11

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!

AttachmentSize
mimemail.rules_.inc_.diff 1.36 KB

#8

jpetso - June 30, 2009 - 06:53

(separating tags by commas, not spaces)

#9

StephenFresh - June 30, 2009 - 14:22

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

criz - June 30, 2009 - 14:35

@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

StephenFresh - July 1, 2009 - 13:18

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

criz - July 4, 2009 - 13:39

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

fago - July 7, 2009 - 15:46

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

criz - July 7, 2009 - 17:03
Status:needs work» needs review

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...

AttachmentSize
mimemail_rules2.txt 10.05 KB

#15

StephenFresh - July 14, 2009 - 12:10

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

seren10pity - July 17, 2009 - 15:05

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

criz - July 21, 2009 - 13:47
Status:needs review» needs work

@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

fago - July 31, 2009 - 12:54

@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

criz - August 14, 2009 - 20:51
Version:6.x-1.x-dev» HEAD
Status:needs work» needs review

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...

AttachmentSize
mimemail_rules_patch4.txt 10.09 KB

#20

jvieille - August 19, 2009 - 17:14

It works very well.
How can we customise the default presentation?

#21

fago - August 24, 2009 - 12:01

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

guysaban - September 6, 2009 - 12:38

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 &nbsp; 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

scottrigby - September 21, 2009 - 04:14

great work jpetso, criz, & fago - I'm looking forward to testing this out ;)

#24

tomski - October 11, 2009 - 13:02

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

criz - October 11, 2009 - 13:01

Hi, did you use the patch from #19? Which rules action did you use?
criz

#26

tomski - October 11, 2009 - 13:31

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

criz - October 11, 2009 - 13:42

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

locomo - October 20, 2009 - 05:24

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

jvieille - November 3, 2009 - 14:34

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

chaumurky - November 5, 2009 - 01:07

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

criz - November 5, 2009 - 02:55

jvieille, do you have used the raw tokens? Just wondering, because rendering html token works for me...

 
 

Drupal is a registered trademark of Dries Buytaert.