I would like to be able to email a node and have the page (either html or pdf) be emailed as an attachment rather than inline html -- is it possible to configure this module in this way? If not, does anyone know what kind of modifications would be necessary to support this? I'm willing to take a crack at it if its not too involved.

The reason for this request is that we are e-mailing invoices (node types) and want it to be fairly easy for our customers to save a copy locally. It's not-so intuitive to do this with inline html.

Thanks!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jcnventura’s picture

Title: Email as Attachment » Option to send node content as an attachment to the e-mail
Status: Active » Postponed

No, the module isn't capable of doing what you're asking at the moment.

It would be a nice addition to have it as well as an option to just send a URL back to the site. Maybe when I have time or someone contributes a patch..

João

ISPTraderChris’s picture

The following patch enables the sending of pages in one of three ways:

1) Inline HTML only (as before)
2) Inline HTML with Attachment (new)
3) Plain Text with Attachment (new)

This option is available after clicking the 'Email' link on a given node. Note that option (2) also sends a Plain Text version for browsers unable to display Inline HTML.

Additionally, this patch adds support for specifying default 'To', 'Subject', and 'Message' text (with Token support) on a per-content-type basis within the CCK content-type edit screen.

** Important **

This patch relies upon (and requires) the PEAR Mail_mime php library. Make sure that you have this installed, and that your path is appropriately configured, before attempting to use this patch.

jcnventura’s picture

Status: Postponed » Needs work

Hi,

First, let me say thank you for such a nice patch. It isn't often that I ask for patches and people actually make them.

However, it isn't quite ready to be applied for the following reasons:

1. It tries to do too much. Please split the patch in two and attach the MIME attachment part to this issue. Create a new issue for the unrelated things and attach the other part of the patch there.

2. Wrap the calls to parts that require the Mail_mime PEAR library in conditions that detect for that library. Like this:

if (@include_once('Mail/mime.php')) {
    // Plan A;
}

3. The new token + content-type-specific settings (which BTW is actually not CCK-specific), is just a big mess. The gravest part is that you're re-introducing security vulnerabilities that were fixed in recent issues. Also, the module is able to deal with non-nodes and one of the first lines in the patch makes a node_load() without checking if this is a node. Also, why is the nid being inserted as a form field if it isn't even used at all, etc, etc.

4. The patch isn't even based on the code in Drupal.org, as the whole first block of changes are to delete some lines which aren't there.

In conclusion, I do like the attachment part (even though I would like to have the option to not send the page at all, and send only the pages's URL. That patch I would review, test and commit ASAP. The rest needs a lot of work before I do more than review it in the browser.

João

ISPTraderChris’s picture

FileSize
3.74 KB

João

1. Done. The attachment patch is below and does not include the token / content-type / default text functionality.

2. Done. Added a section to the form validation function to throw a form error if an attachment option is selected and the library is not detected

3. I have to admit, this comment is far from constructive. I do believe this functionality will be valuable. I will post it separately in a new issue in the hope you can provide more specific feedback there. I am not familiar with the security vulnerabilities you mention, but I'm sure I will be able to update and resolve.

4. This is entirely my mistake, I thought I had patched against an unmodified release version when I actually patched against a version I had modified. This has been resolved.

Regarding emailing only the link to the page, this is a very minor addition to my patch. As this is not functionality I specifically require, it would be helpful if you could provide me some more details on how you would like this to work. Would the link simply be appended to the end of email message?

Thanks,
Chris

ISPTraderChris’s picture

Also, to anyone testing this patch please note: The emails will NOT be sent with the correct MIME formatting if you are running the SMTP Authentication module. I spent a half a day tracking this problem down myself. Basically, this module attempts to rewrite MIME headers before sending any emails, and does so incorrectly. I'm not sure why it was written this way, and I have posted this issue to the SMTP issues queue as well - but be warned. We had to disable this module in order to send properly formatted emails.

jcnventura’s picture

Status: Needs work » Needs review

I'll probably add the library check in the admin form before presenting this option to the user, but other than that (and the URL-only option), I only need this to be reviewed by me and/or others.

As to the URL-only option, it's simply that.. Instead of sending the node contents, force a visit to the site by providing an "a href" link with the original page URL with the anchor text being the page title. The mail itself would still be HTML, or a plain text version.

João

PS: As to the 3rd point in my previous comment, indeed it wasn't very constructive. I will try to finish this patch and some minor ones and then I will take a deeper look at the other issue, where I hope to be more constructive. You can easily identify the security fixes you re-introduced by searching for filter_xss in the patch and looking for the lack of that function in the new lookups of the variables being sanitized in the old code.

ISPTraderChris’s picture

FileSize
5.64 KB

Updated to include "Send Page As Link" option. This option will work with or without the PEAR Mail/Mime.php library installed. With the library installed, messages will be sent in both HTML and Plain-Text formats for clients that do not support HTML. Without the library messages are sent in HTML format only.

peterx’s picture

I tried the #7 patch. The send link works. Plain text with attachment produces:
Fatal error: Class 'Mail_mime' not found in /sites/all/modules/print/print_mail/print_mail.inc on line 373

jcnventura’s picture

Status: Needs review » Needs work

That would be because you don't have the Mail_Mime library installed.

Looking at the code of the #7 patch, where it's written:
switch($form['fld_send_option']) {
should be
switch($form_state['values']['fld_send_option']) {

Note that I have just written the above by looking at the code, so it may not even work like that.. You should now be denied the option to set the "* with Attachment" options in the settings page.

ISPTraderChris’s picture

Status: Needs work » Needs review
FileSize
5.66 KB

I have updated the patch to fix the library validation code -- jcventura is correct, it should be $form_state['values']['fld_send_option'] -- this should throw a form validation error when attempting to send an email with an attachment if you do not have the PEAR Mail_Mime library installed.

peterx’s picture

The patch now highlights the Send page as field in red and produces the messages:
* warning: include_once(Mail/mime.php) [function.include-once]: failed to open stream: No such file or directory in /home/example/public_html/sites/all/modules/print/print_mail/print_mail.inc on line 243.
* warning: include_once() [function.include]: Failed opening 'Mail/mime.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/example/public_html/sites/all/modules/print/print_mail/print_mail.inc on line 243.
* The PEAR Mail_mime library is required for this send option and was not found.

I installed PEAR Mime mail using Cpanel and the module was installed in path /home/example/php. I then found the WHM PEAR installer which installs the module in the right place and the email worked.

The received email was not in the format I was expecting. I will open a separate issue about the format.

jcnventura’s picture

Status: Needs review » Needs work

Well, instead of trying to check for the include file, it would be better to check for class_exists() as that won't produce the warnings. I really have to find some time to try this... Unfortunately, I am in the same boat as you are, as that library is not installed in my test system, so I guess I will test that aspect first. :)

João

ISPTraderChris’s picture

Status: Needs work » Needs review
FileSize
5.64 KB

Updated to check for the Mime_mail class via class_exists() to suppress warnings.

arski’s picture

hey guys, whats the status of this?

asak’s picture

yea - this is pretty cool.. what's up? ;)

ISPTraderChris’s picture

I've been running this patch in production for some time with no issues -- but we haven't really received feedback from anyone else who has also tested it out.

olbion’s picture

As someone noted, this isn't compatible with the SMTP module. After a lot of fiddling I found out there's an alternative to SMTP - http://drupal.org/project/phpmailer. Got this set up together with the Mime module and now it's working fine!

jcnventura’s picture

Status: Needs review » Fixed

Thanks for the patch. I've just committed it to CVS.

Sorry that it took almost a year :)

Vako’s picture

Would it be possible to change the default? currently it is defaulting to Plain Text with Attachment.

Thanks!

jcnventura’s picture

I guess that no default will be OK. So indeed, I've added an option to the email settings form.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

johnv’s picture

Version: 6.x-1.9 » 7.x-1.x-dev
Status: Closed (fixed) » Patch (to be ported)

In D7, I only have the options 'Link' and 'Inline HTML'. Must this patch still be ported, or do I need to install/activate other parts of the module/library?

jcnventura’s picture

Status: Patch (to be ported) » Closed (fixed)

It must still be ported. But D7 still needs a lot of work anyway.. When I sync D6 to D7 that will be added.

Roze-1’s picture

Is it possible to attach as PDF instead of HTML ?