Community & Support

Module for emailing entire nodes?

We have some nodes that we would like to mail out periodically in a newsletter. Is there a good solution for just e-mailing the nodes, instead of having to create a new newsletter node and e-mailing that?

Comments

...

I'm not aware of an off-the-shelf solution for this. However, it is fairly easy to get the SimpleNews module to provide this behavior (assuming you have a decent grasp on PHP, Drupal, template files, and the SimpleNews module.) I've done this for a handful of sites with good results.

Essentially, you want to add fields (using CCK) to the SimpleNews node type that allow you to attach nodes, and then customize the node-simplenews.tpl.php template file to format the attached contents to your liking.

One way would be to simply add a node reference field to the simplenews node type, and then reference the node(s) you want to include in the newsletter. Another (slightly more complex) option would be to set up a list of nodes using the Node Queue module to designate which nodes should be displayed for each newsletter.

Great thing about this is that you still get to use the SimpleNews module features for managing subscriptions, generating emails, etc. The only real work is in customizing the node-simplenews template to display the nodes within the newsletter the way you want them.

Thanks!

Thank you for the answer. I had taken a look at SimpleNews originally, but dismissed it without even thinking of adding node reference fields. I will take a closer look at this.

double post

Overly anxious clicking.

Followup Question re: node reference fields

I am still trying to get this to work correctly. I have added the node reference field to my newsletter, and I made sure to change the "Display Fields" setting to include the whole node. However, when I send the newsletter, the actual e-mail only contains links to the nodes. The node created on the site displays the entire nodes correctly, however. Any idea on what might be wrong? Is there something else I need to do in the the template file? Thanks for your help.

...

Yep, you're gonna' have to do some work on the template files...

When you view a newsletter online, it goes through the 'normal' node template process. As a result, you can modify the look of the online newsletters by copying your theme's node.tpl.php file to node-newsletter.tpl.php, and then altering this template to your liking. Better yet, use something like this to create a page-newsletter.tpl.php file where you can customize the entire page layout of online newsletters. But if the newsletters already display online the way you want, you may not have to do anything here.

As for the actual emailed newsletters, you'll need to modify the simplenews template files. The important one is simplenews-newsletter-body.tpl.php. And Drupal probably won't look for this template in your theme's folder, so you'll have to modify the one in the simplenews module folder.

As for the actual changes, you're going to want to add to or replace the:

<?php
print $body;
?>

statement from the template with something else. Say, for example, that you add a node reference field called 'field_newsletter_story' to your simplenews content type, and you allow multiple values to be specified (thus allowing you to add an arbitrary number of nodes to your newsletter)... then the following code would display each of these nodes in your newsletter (with node titles as links, no less):

<?php
 
foreach ($node->field_newsletter_story as $story) {
   
$next_node = node_load($story[nid]);
   
$node_link = $GLOBALS['base_url'] . '/node/' . $next_node->nid;
    print 
'<a href="' . $node_link . '"><h2>'. $next_node->title . '</h2></a>';
    print
$next_node->body;
  }
?>

With a little bit more code, you can customize the newsletter to include multiple node types and an entirely distinct layout. I've used this method to create entirely unique page layouts for emailed newsletters.

Keep in mind that formatting HTML for email clients is a whole different world than formatting HTML for web pages. Take a look at:

http://www.sitepoint.com/article/code-html-email-newsletters/

Perfect!

Wow, that was exactly what I was looking for. I am just getting into theming, so it is very helpful to have someone hold my hand through this complicated process.

Thanks for this..
I am wondering how I could print the individual CCK fields' content of the nodes that are referenced (in the actual email sent by Simplenews)?
It displays fine on the web-based node view. Not in the email though. Any thoughts?

Example:
I am building a portfolio site.
The artist wants to send out a manual newsletter via Simplenews HTML email on irregular basis, with his latest nodes (full-body/all fields) in the e-mail.

I have a content-type called 'folio_item', used by the artist to enter a main-image and multiple secondary images for his portfolio entries.
The 'folio_item' content-type contains 2 cck fields: 'field_mainimage' (only 1 (filefield) image allowed) and 'field_secondaryimages' (unlimited (filefield) images possible) and a few other unimportant CCK text fields.

I've added a node-reference cck field called 'field_newsletteritems' to the Simplenews 'newsletter' content type, and allow for unlimited 'folio_item' types to be referenced.

As mentioned by Jergason, I am also able to see the fields properly in the web-based view.
But they don't display in the email. i only see linked node titles.

Based on your example above, I'd like to make it look something like this:
Note that the 4-lines beginning with 'print $node->content.....' are the lines I have added (I realize the code is wrong but this is the best way I can clearly describe what I am trying to do.

<?php
 
foreach ($node->field_newsletteritems as $story) {
   
$next_node = node_load($story[nid]);
   
$node_link = $GLOBALS['base_url'] . '/node/' . $next_node->nid;
    print 
'<a href="' . $node_link . '"><h2>'. $next_node->title . '</h2></a>';

   print
$node->content['field_mainimage']['#value']
   print
$node->content['field_secondaryimages']['#value']
   print
$node->content['field_myccktextfield']['#value']
   print
$node->content['field_mycckdatefield']['#value']

    print 
'<br />';
    print 
'<br />';
    print
$next_node->body;
  }
?>

Thus the email received should look like this:

*****
-Newsletter_title

Folio_item 1 node-title (linked node-title)
Folio_item 1 mainimage (linked image showing)
Folio_item 1 secondaryimage-1 (linked image showing)
Folio_item 1 secondaryimage-2 (linked image showing)
Folio_item 1 myccktextfield (text)
Folio_item 1 mycckdatefield (date in plain-text)

-

Folio_item 2 node-title (linked node-title)
Folio_item 2 mainimage (linked image showing)
Folio_item 2 secondaryimage-1 (linked image showing)
Folio_item 2 secondaryimage-2 (linked image showing)
Folio_item 2 myccktextfield (text)
Folio_item 2 mycckdatefield (date in plain-text)

-

Folio_item 3 node-title (linked node-title)
Folio_item 3 mainimage (linked image showing)
Folio_item 3 secondaryimage-1 (linked image showing)
Folio_item 3 secondaryimage-2 (linked image showing)
Folio_item 3 myccktextfield (text)
Folio_item 3 mycckdatefield (date in plain-text)

(End of email)

*****

Any help would be greatly appreciated.
Thanks a lot

Pierre