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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

criz’s picture

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

criz’s picture

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

criz’s picture

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

jpetso’s picture

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.

fago’s picture

Issue tags: +rules integration

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.

fago’s picture

ah, and does mimemail remove "\r" and "\n"? As the patch does it only on configuration time, but this wouldn't apply to tokens.

aantonop’s picture

Issue tags: -rules integration
FileSize
1.36 KB

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!

jpetso’s picture

(separating tags by commas, not spaces)

StephenFresh’s picture

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

criz’s picture

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

StephenFresh’s picture

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?

criz’s picture

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

fago’s picture

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.

criz’s picture

Status: Needs work » Needs review
FileSize
10.05 KB

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

StephenFresh’s picture

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.

seren10pity’s picture

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 !

criz’s picture

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

fago’s picture

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

criz’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Needs work » Needs review
FileSize
10.09 KB

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

jvieille’s picture

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

fago’s picture

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.

guysaban’s picture

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.

scottrigby’s picture

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

tomski’s picture

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

criz’s picture

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

tomski’s picture

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

criz’s picture

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

locomo’s picture

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!

jvieille’s picture

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

chaumurky’s picture

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?

criz’s picture

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

EvanDonovan’s picture

Subscribing. I plan to test this in the next few days.

BenK’s picture

Subscribing too...

jferjan’s picture

subscribing

EvanDonovan’s picture

Forgot to mention - I tested the patch from #19 and it is working excellently, although I had to manually apply it. It was a while ago now, but I think what happened was that it created the includes in the wrong subdirectory.

nickgs’s picture

I have tested the patch from #19... works great!

I am using tokens extensively in my emails. The HTML is being attached to the emails, is this the desired functionality? I think it would be nice to have the HTML message embedded in the body of the email.

Thanks.

Nick

wisniewski’s picture

This path is great, and will be even more powerful with some nice features:

- support HTML Mail Template (/admin/settings/htmlmail/template)
- support Input Filter (eg. Full HTML)

Now I add files through PHP code - load node with attached files and copy proper MIME and file location, this is quite simple and I wonder how to make it even simpler.

Regards
Kristof

geerlingguy’s picture

Subscribe.

tobiberlin’s picture

subscribing

Aren Cambre’s picture

TripleEmcoder’s picture

Subscribing.

wisniewski’s picture

It does not work with patch:

http://drupal.org/node/358439#comment-1426276

and sends attachements only with the first mail in Rule Set.

criz’s picture

@infotrendy
Please provide some more info. Attachements in rulesets are only working once? Is there always the same file attached?
http://drupal.org/node/723072#comment-2641530 is working now?

wisniewski’s picture

It was the problem described here:
http://drupal.org/node/358439#comment-1426276
So only the first mail in Rule Set (or just first execution of mimemail()) is send with attachments - I used the same files every time.

The problem in #42 was due to overpatching mimemail with more patches, now I use combination of
http://drupal.org/node/501722#comment-1925296
http://drupal.org/node/358439#comment-1426276
on 6.x-1.0-alpha1
and works great with Rules, it would be good to include this in next release.

aaron’s picture

didn't see this issue earlier. there's also a patch for review at http://drupal.org/node/727210 adding rules + token support to mail logger.

sgabe’s picture

FileSize
10.21 KB

With the Mime Mail template file the message will contain the <html> and <body> tags twice. The default value of the HTML message should rather be empty. The attached patch is #19 with removed default value of the field in question.

<html>
  ...
  <body id="mimemail-body">
  ...
  <html><body><p>Lorem ipsum dolor sit amet</p></body></html>
  ...
  </body>
</html>

Aside from this, it looks fine.

mennonot’s picture

When I install the patch in #46, everything works as expected up to the point after I have created the "Send an HTML email to an arbitrary email address" DO section in the rule elements. The email is sent formatted in html with the tokens as expected (with the exception of node_body).

However, where I return to edit the fields in the "Send an HTML email to an arbitrary email address" section, the "Subject" and "HTML message" fields are blank, even though they obviously are saved in the database.

mayerwin’s picture

Was this patch applied to the latest release?

sgabe’s picture

@mayerwin: If you take a look at the patch, you will see that it creates 2 new files and doesn't modify anything. So the patch applies fine on any 6.x version.

jday’s picture

RE: #28 carriage returns get stripped out of the plain text version

is there a reason to change carriage returns into spaces? It's really hard to read the non-html version without line breaks, so I'm wondering if commenting out line 135 would have any negative consequences, seems like a good idea to me

criz’s picture

@jday
yes this is a kind of issue actually. Have to find out if this str_replace is really necessary for security reasons...
Any ideas someone?

sgabe’s picture

Status: Needs review » Needs work

Changing status.

UNarmed’s picture

Great going to give this a try now! =D

jday’s picture

has anyone gotten the cc and bcc fields to work? when I have the cc field filled the value is displayed on the main recipient's email as getting cc'd but the email is not actually sent to the cc email in that field. And email addresses in the bc field also do not get the email.

criz’s picture

@jday
this should be working. take in mind that some mail provider send a mail only once to an e-mail address, even if bc or cc. tried with a different e-mail addy?

EvanDonovan’s picture

I think that the bcc works for our organization's implementation, but I would have to confirm with my coworkers to be 100% sure.

jday’s picture

thanks all for the replies!

I have set up different emails for each (recipient, cc, bcc) and it looks like the recipient and cc fields are working, so just the bcc is not working according to my tests. I went into mimemail.rules.inc and changed all instances of 'bc' to 'bcc' but there was no change in results so I changed it back.

PipB’s picture

I've got a problem with installing Mimemail in Drupal 6.16 with rules, views, and a lot of other modules.
After installing I could not save a node that triggers the mail-action-rule and got a white webpage: error 500....
After that I found an advice on the forum about a module: htmlmail > (http://drupal.org/node/553466). I've installed it and it works perfect for appending new lines in de mail-body with "< br/ >".
Maybe easier for people who only wants a HTML message in the body-mail.

criz’s picture

Status: Needs work » Needs review
FileSize
9.9 KB

Finally I did a reroll of this patch based on #46.
- #50 no more stripping out /r and /n in mail body and mail body text, so the text version works fine with returns
- #21 variable settings['bc'] is now $settings['bcc']
- #21 renamed settings_validate to settings_process
- #21 leaving $user unset

Tested all three actions and all form fields (incl. bcc) successfully with rules 6.x-1.2 and mimemail HEAD.

vstmusic’s picture

It works, but the body of the email is strange. It includes the size and image of the body of the website. Is it possible to hide that ?

criz’s picture

@vstmusic
this seems to be default mimemail behaviour.
Place a mail.css file in your theme base directory, then Mimemail includes that instead of all the CSS files of your default theme. http://drupal.org/node/614782

sgabe’s picture

@vstmusic: About that see #685574: Optional site's css embedding.

vstmusic’s picture

There seems to have a bug : When I use the form created by your file "Send an HTML mail to a role" and I save it, the content of form (sender, message) is BLANK when I come back to the form (after saving) for example for editing the rule.

Do you understand my problem ?

sgabe’s picture

Status: Needs review » Needs work

@vstmusic: You are not the only one who is experiencing that, see #47. I think this still needs work then.

criz’s picture

I can't reproduce this. Please add a new action and test it with this one. Thx.
criz

vstmusic’s picture

How can I "test" it ?

criz’s picture

Do you have the latest rules module version 6.x-1.2?
Did you use the patch from #59?
Does the problem persist if you add a completely new rule/action?

vstmusic’s picture

I confirm the bug ! with 6.x.1.2 and #59 and new rule =>Blank forms

sgabe’s picture

@vstmusic: I can't reproduce it either. Can you give us step-by-step instructions? It's okay if the forms are blank when you add a new rule, see #46 above. The problem is if an existing rule's setting is vanishing... Is this what you experience?

vstmusic’s picture

1. I create a new rule with an action : "Send an HTML mail to a role".

2. I fill the subject field and the HTML message field.

3. I save the rule. (and I test that the message is correctly send)

4. When I want to edit my rule, I click again on my rule and on my action =>

5. Oh ! All is empty (invisible).

Do you understand ?

sgabe’s picture

@vstmusic: I followed your instructions, but when I go back to edit the rule, the action fields are filled just as I saved them...

vstmusic’s picture

strange ! I don't understand....

Aren Cambre’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev

Isn't this going into 6.x?

sgabe’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev

@Aren Cambre: There is no available 6.x-1.x development branch right now. The action is in HEAD so patches should be made against that.

YK85’s picture

subscribing

corbacho’s picture

My tests:

Mime Mail 6.x-1.0-alpha4 with patch #59
Rules 6.x-1.2

I tried also the steps of #70 and couldn't replicate error
And Bcc field is working for "Send an HTML mail to an arbitrary mail address"

So for me is working perfectly, these actions are very useful and will be great to have them in the module. It's by far the best alternative I found for automated notifications: Rules + Token + Mimemail rocks

criz’s picture

Status: Needs work » Reviewed & tested by the community

Using patch #59 also for a month now on various sites. Working great...

jvieille’s picture

I am still running 19 - perfect

Nathaniel’s picture

Mime Mail 6.x-1.0-alpha4 - manually installed patch #59
Rules 6.x-1.2

Tested on two different websites. Works great!

chaumurky’s picture

Just a quick one, when I run patch -b -p0 < mimemail_rules_59.patch I get the following:

(Stripping trailing CRs from patch.)
patching file includes/mimemail.rules.inc
patch: **** malformed patch at line 149: Index: includes/mimemail.rules_forms.inc

Anyone had this? Any way around it?

sgabe’s picture

Status: Reviewed & tested by the community » Needs work

Thanks for some changes in the past commits the patch could use some work:

  • Specify a mailkey for the messages.
  • Specify list value for the attachments (only listed elements will be attached).
  • Rule function names should be simplified, the actual state is unnecessary verbose IMHO.
  • Watch out for code formatting issues.
twistedindustries’s picture

Using 59, I am also experiencing the blank form glitch. The only thing that seems to stay is the
Recipient:
CC Recipient:
BCC Recipient:
fields, all else are always blank on edit.

twistedindustries’s picture

I switched to #19 and it seemed to help.

sgabe’s picture

Status: Needs work » Needs review
FileSize
10.24 KB

Attaching a new patch according to #81. I see Rules uses verbose function names for actions, then we shall stick with that.

jday’s picture

just upgraded to mimemail 6.x-1.0-alpha6
applied patch in #84

there's a problem now when using a rule to send html email:
the bcc field does not convert tokens or evaluate php

criz’s picture

Tested patch from #84 and it worked fine. No problems with evaluating php or form default values.

jday’s picture

FileSize
14.91 KB

I have a rule that sends an email to three different addresses:

To: emailA
CC: emailB
BCC: emailC

emailA and emailB are sent, and looking at the 'recent log entries' is this:
"Successfully sent HTML email to emailA, [node:field_emailC-raw], emailB"

If I switch it up so that emailB is the bcc and emailC is in the CC field, then emailA and emailC are sent but not B
log entry:
"Successfully sent HTML email to emailA, [node:field_emailB-raw], emailC"

the token value for the bcc was not getting converted to the actual value

FOLLOW UP
after deleting my rule and creating it from scratch, the bcc functions as expected. weird - but at least it's working now, whew

dontgoquietly’s picture

Category: feature » support

Hi, I have not been able to get this to work yet. I have tried putting the two patch files in the mimemail includes, in the rules modules subfolder, and in both cases ran update.php - but the form is not altered on the add a new action screen.

using
Mimemail 6.x-1.0-alpha6
Rules 6.x-1.2

is there something I'm missing? Do I need to write an include somewhere?

sgabe’s picture

Category: support » feature

This is still a feature request.

YK85’s picture

Hi, I was wondering if there a newer patch that may be tested? Or the module+patch that the community may test?
Being able to send HTML emails via Rules would be great!

sgabe’s picture

@dontgoquietly: You need to apply the patch in #84 to Mime Mail, see Applying patches for more information about how to do that.
@yaz085: Did you test the one in #84? What did you experience?

criz’s picture

@jday
Do you have reconfigured your rules after applying the patch? Token and PHP evaluation seem to work for me.

sgabe’s picture

Status: Needs review » Reviewed & tested by the community

Since there isn't any new bug reported and the patch seems fine, I am marking this as RTBC. Please confirm or confute.

jvieille’s picture

For me, it is ok since #19...
Waiting for the committ!

sgabe’s picture

Status: Reviewed & tested by the community » Fixed

Patch in #84 is committed to HEAD with minor changes (doxygen marks, etc). Thanks for the work, everyone!

butler360’s picture

So if I use a CCK field token for sender or recipient it should work, right? Because if I use a token in one of those fields I get this:

Please enter a valid e-mail address for recipient.

Aren Cambre’s picture

Status: Fixed » Needs work
sgabe’s picture

Status: Needs work » Closed (fixed)
zaurav’s picture

I tried #84 with 6.x-1.0-alpha6 and am getting the email ok, however the attachment isnt getting attached.

I'm trying to use "[node:field_pics-filefield-filemime]:[node:field_pics-filefield-filepath]" in the attachment field. I even replaced that with "image/png:sites/default/files/1.png" but to no avail.

Tokens in the HTML field are working fine.

I'm on Drupal 6.x-19

Edit: I'm sorry, the problem was I was including double quotes in the attachment field. That fixed it.

Offlein’s picture

Subscribing - And curious if this will support Input Formats / Filters -- I just want mine to integrate with WYSIWYG.

Offlein’s picture

Er. Sorry, I see this is closed. I made a new issue: #1108324: Add input filter to HTML message for system and Rules actions

narcisgirona’s picture

I'm having trouble in order to get it work. Could you please help me a bit?

I have created a rule which sends an HTML email whenever a user posts an article. Everything seems to work but the attachments. I want to send the images the user posted on the article to the email but can't figure out how to do so. Again i'm able to send the body of the article, title (everything) but not the attachet images of the posted article.

I'm sure i'm doing something wrong on the section where i have to setup the attachments:

Attachments
The mail's attachments, one file per line e.g. "files/images/mypic.png".
Value
[

here i should use the path or token but have no clue how to implement it

]

Thanks man, hope to hear about you soon.

jday’s picture

@narcisgirona
Get the token from the "Token replacement patterns" list, find the token for your image field
something like this: [node:field_image-filepath]

narcisgirona’s picture

FileSize
307.31 KB

Hey @jday thanks for you help but unfortunately still not working.

on the Token replacement patter i just get one token [node:field_image]

here you have some screenshots:

THANKS for your help!

narcisgirona’s picture

I managed to make it work however just with and absolute path defined in the attachaments value:

If i save a file the file /sites/default/files/file_example.jpg then i would get the email with attachments but if i'm using the tocken:

[node:field_image] instead of /sites/default/files/file_example.jpg But i'm not getting the attached files.

I guess i should use [node:field_image:path] or something like that but can't find the option anywhere.

i tried with a few combinations:

[node:field_image:path]
/sites/default/files/[node:field_image]
/sites/default/files/[node:field_image:path]
/sites/default/files/"[node:field_image]"
"/sites/default/files/[node:field_image:path]"
...

Any help would be much apreciated

thanks