Right now the user has to fill the message (subject & body) at the send phase. We need an alternative provided through UI so that the user can choose between filling the message or, simply, picking up an existing node.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Peng.Pif’s picture

Yes, this will be great and save a lot of time if the body field is quite long. Also, if there are numerous messages that need to be sent out to various users on the site it could be tedious having to copy / paste text into the body field for the Admin.

If there was a way to have a node type associated with the module, Admin's could create various messages (nodes) and then select which one they want to send from a drop down when sending out a mail.

Do you need help with this?

claudiu.cristea’s picture

I imagine something like...

  1. Admins can select the content types that can be selected - one or many
  2. User can choose to enter the text (like it works now) or choose the node with an autocomplete but only from types defined at 1.
  3. A 2 options element: 1=Render as node; 2=Render as page (page view of that node)

The 3. step means that you can send only the node as body (node.tpl.php) or you can send the whole page (node in the page view). In the last case you can use separate templates for desired node types (see http://drupal.org/node/249726) like: page-node-story.tpl.php

What you think?

Peng.Pif’s picture

Hi, that sounds good.

If a admin selects a content type, for example Message, will the email be able to send out more fields than just Node Title and Node Body? The only reason i ask is if there are more fields available, then pre-defined fields from CCK can be used in that content type.

claudiu.cristea’s picture

It will send out the themed node. This mean all data with the same theming that is viewable as node.

eliosh’s picture

I think it will be a great feature.

pvhee’s picture

Looking forward to use template emails as well. Basing them on existing nodes with token integration is a great idea.

patcon’s picture

Great module!!! Views Mail was wonderful, but the implementation seemed a little cobbled together or hackish (no disrespect intended to the wonderful maintainer). This seems to be a step in the right direction.

Agreed that sending nodes seemed pretty important. What about integrating with simplenews to send newsletters nodes?

roball’s picture

Yes, associating node types with Views send would be a very useful enhancement.

ademarco’s picture

FileSize
674 bytes

I've been working on a module called Views Send Node which implements what described in this feature request, you can find it here:

http://github.com/ademarco/views_send_node

For a quick overview have a look at the README.txt, I'm planning to release it as soon as possible.

Nevertheless I had to patch Views Send in order to add $mailkey to _views_send_prepare_mail() call. Doing so allows the module to use its own implementation of mimemail.tpl.php, a necessary step to have full control over the final email template (see README.txt).

I now set "views_send_direct" as mailkey, but, as this TODO states:

/**
 * TODO: In the future, this module will be able to send an existing node.
 * $key will have to make the difference. A value when we pickup a node, other
 * when user inputs the subject & body of the message.
 */

the mailkey must depend on which method we actually use to send the email: direct or by selecting a node. I can work on a better patch if you are interested, for the moment the quick fix is attached (patched against HEAD).

claudiu.cristea’s picture

@antoniodemarco I don't understand why you choose to build a separate module? It would have been better if you tried to create a patch against this module.

roball’s picture

Yes, agreed. Druapl already has way tooo much modules needed to implement a few features.

ademarco’s picture

I could have made a patch but Views Send has not stable releases yet and creating another module is just more maintainable. It's ok for me to make a patch out of it but I'd like to discuss with you its design before, so for the moment help me testing this module and give feedback, once it's stable i'll roll out a patch.

patcon’s picture

Status: Active » Needs review

Great effort antonio! Sounds like a really interesting take! I agree that splitting efforts is not the best way, but in your defence, you're sort of working in the way that I expect we'll all be working once git is implemented, right? Fork your own branch, implement the feature you want to, then offer to have it pulled back in? Maybe a bit more dialogue would have been better, but it's looking like you're on that route now :)

Thanks for the contribution regardless -- I'll try to help test it when I get some free time

ademarco’s picture

Thanks Patrick for the words! Let's indeed focus on testing it being sure it really does what we want, then it will not a big deal turning it into a patch.

ademarco’s picture

I've made a patch out of the latest version of the Views Send Node module available on Github. Patch is against DRUPAL-6--1 branch of the Views Send module. Now you can:

1. Enable a content type to be "sendable"
2. Preview email as node content or as separate page
3. Send test email from within the node edit page
4. Receive HTML email with the node as content

Refer to README.txt for the full list of changes.

ademarco’s picture

Some screenshots illustrating the main changes. EDIT: the second "Send test email from within the node edit page" should have been "Preview email as node content or as separate page".

patcon’s picture

You're amazing Antonio. I'm a little busy with something else right now, but I'll try to test it out for you sometime!

ademarco’s picture

I attach an updated version of the patch which adjusts the module's behavior in case the Mimemail is not enabled. It also fixes a validation error in "Send content by email" action form.

claudiu.cristea’s picture

Hi. The patch look great. I will be out in holidays next 10 days so I will review the code when I will get back... A single point right now: I saw the nodes are sent instantly through hook_nodeapi(). This is somehow against how Views Send is build. Sending bulk messages instantly is quite dangerous. So IMO it's better to queue also node mails in the spool table. Consider this please.

Thanks again for this great work.

ademarco’s picture

Hi Claudiu, I actually use hook_nodeapi() only to send test messages to one test email, it helps editors to test the final result. The the VBO action the patch implements does use the spool table, 100% Views Send style.

Glottus’s picture

subscribing

jayson’s picture

This is going in a great direction! I've been using Simplenews for a while, but would really like to have the ability to personalize emails with first and last name or full name, but it doesn't seem to be happening with Simplenews despite a lot of discussion.

Do you guys think this is possible with this module?

If I installed Content Profile to have user profiles as nodes, added first and last name fields to the content type as well as a single checkbox called "Subscribe me to receive email notifications", and exposed those three fields on the user account creation form - then I wouldn't need a newsletter signup form or even Simplenews for that matter. The account creation form would serve as the newsletter signup form. Then I could email out any node to any list of email addresses and have all the emails personalized using tokens for first name and last name. If you send out a node, can you add greeting personalization with tokens?

Is that possible now?

ademarco’s picture

Hi Jayson,

that's exactly the way I use it and the reason for making such a patch. What I would suggest is to use the patched module in combination of Mimemail and Views module and to embed a view in the module's provided TPL. Quoting the README.txt:

CUSTOMIZATION

Views Send gives you the possibility to send rich HTML emails. You can
customize your emails' look and feel by copying and modifying the following
files in your theme directory:

views_send_node/themes/mimemail-views-send-node.tpl.php
views_send_node/themes/mimemail-views-send-node.css

Views Send gives you the possibility to specialize the template and its
relative CSS per content type. To do so add the following files to your theme
directory:

mimemail-views-send-node-<CONTENT-TYPE>.tpl.php
mimemail-views-send-node-<CONTENT-TYPE>.css

So you would create, in your theme dir:

mimemail-views-send-node-mycontenttype.tpl.php
mimemail-views-send-node-mycontenttype.css

and then in your template.php:

/**
 * Implementation of preprocess callback.
 */
function mytheme_preprocess_mimemail_message(&$vars) {
  $node = views_send_node_get_node();
  $vars['header'] = views_embed_view('user_profile', 'block_1', $node->uid);
}

and, in mimemail-views-send-node-mycontenttype.tpl.php, something like:

...
<table id="header" width="" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="header-left"><div class="inner"><?php print theme('image', drupal_get_path('theme', 'mytheme') .'/email/logo.png'); ?></div></td>
    <td class="header"><div class="inner"><?php print $header; ?></div></td>
  </tr>
</table>

<div id="content"><div class="inner">
  <?php print $body ?>
</div></div>
...

This is taken from a real life example, the user_profile block_1 views display shows user's picture, first and last name. One thing: make sure you start theming from the default "mimemail-views-send-node.tpl.php".

roball’s picture

This patch seems to be very amazing. I just tested it applying against the latest official dev, but the annoying critical bug #808058: HTML messages are sent as plain-text including (visible) HTML-tags prevented this improvement to be testable (the received HTML email is garbage). If I revert the patch from http://drupal.org/node/808058#comment-3101134, then this patch (http://drupal.org/node/796694#comment-3230146) won't apply :-(. As long as #808058: HTML messages are sent as plain-text including (visible) HTML-tags won't be fixed, we are blocked here too.

claudiu.cristea’s picture

Status: Needs review » Needs work

Great features/improvements to come :)

+++ README.txt	21 Jul 2010 13:30:17 -0000
@@ -28,6 +28,59 @@ USAGE
+email" which allows to select and send nodes as email.

On Drupal we type "E-mail". Please use this form in code & docs.

+++ README.txt	21 Jul 2010 13:30:17 -0000
@@ -28,6 +28,59 @@ USAGE
+Views Send provides a Views Bulk Operation action called "Send content by
+email" which allows to select and send nodes as email.
...
+In order to sen a node as email its content type has to be exposed to Views
...
+Views Send gives you the possibility to send rich HTML emails. You can

+++ views_send.module	21 Jul 2010 13:30:18 -0000
@@ -456,6 +620,139 @@ function views_send_form_alter($form, $f
+      '#title' => t('Send as Email'),
...
+      '#title' => t('Send test email'),
...
+      '#title' => t('Send email after saving'),
...
+      // Prepare and send email.

@@ -995,6 +1306,81 @@ function _views_send_allow_php() {
+ * Get email body and set a reference to the current node. ¶
...
+ * Get email content types

On Drupal we type "E-mail". Please use this form in code & docs.

+++ themes/mimemail-views-send-node.css	21 Jul 2010 13:30:18 -0000
@@ -0,0 +1,46 @@
+body {

Start the CSS file with CVS Header:

/* $Id$ */

+++ themes/mimemail-views-send-node.css	21 Jul 2010 13:30:18 -0000
@@ -0,0 +1,46 @@
+}

Add a new line at the end of the file http://drupal.org/coding-standards#indenting

+++ themes/mimemail-views-send-node.tpl.php	21 Jul 2010 13:30:18 -0000
@@ -0,0 +1,39 @@
+</html>

+++ themes/page-views-send-node-preview.tpl.php	21 Jul 2010 13:30:18 -0000
@@ -0,0 +1,8 @@
+<?php print $content; ?>

Add a new line at the end of the file http://drupal.org/coding-standards#indenting

+++ themes/page-views-send-node-preview.tpl.php	21 Jul 2010 13:30:18 -0000
@@ -0,0 +1,8 @@
+<?php print $content; ?>

Add a new line at the end of the file http://drupal.org/coding-standards#indenting

+++ views_send.module	21 Jul 2010 13:30:18 -0000
@@ -56,10 +70,67 @@ function views_send_action_info() {
+      'description' => t('Send content by email'),

Type "E-mail" form.

+++ views_send.module	21 Jul 2010 13:30:18 -0000
@@ -56,10 +70,67 @@ function views_send_action_info() {
+

Too many \n

+++ views_send.module	21 Jul 2010 13:30:18 -0000
@@ -365,10 +439,53 @@ function views_send_menu() {
+  $items['node/%node/email'] = array(

Add the "description" field.

+++ views_send.module	21 Jul 2010 13:30:18 -0000
@@ -365,10 +439,53 @@ function views_send_menu() {
+    'title' => t('Email preview'),

* The 'title' & 'description' should not be translated. The Menu System will do this automatically.
* Type "E-mail" form.

+++ views_send.module	21 Jul 2010 13:30:18 -0000
@@ -365,10 +439,53 @@ function views_send_menu() {
+  $items['node/%node/email/iframe'] = array(

Add the "description" field.

+++ views_send.module	21 Jul 2010 13:30:18 -0000
@@ -365,10 +439,53 @@ function views_send_menu() {
+    'title' => t('Email iframe preview'),

* The 'title' & 'description' should not be translated. The Menu System will do this automatically.
* Type "E-mail" form.

+++ views_send.module	21 Jul 2010 13:30:18 -0000
@@ -390,10 +508,56 @@ function views_send_theme($existing, $ty
+ * Implementation of hook_theme_registry_alter().
...
+ * Implementation of hook_preprocess_page()
...
+ * Implementation of hook_preprocess_node()
...
+ * Implementation of hook_preprocess_mimemail_message()

Add reference to the API resource

Example:
@see http://api.drupal.org/api/function/hook_theme_registry_alter/6

+++ views_send.module	21 Jul 2010 13:30:18 -0000
@@ -456,6 +620,139 @@ function views_send_form_alter($form, $f
+  // Enable a content type to be "sendable"
+  if ($form_id == 'node_type_form') {
+    $form['views_send_node'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Send as Email'),
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+      '#weight' => 32,
+    );
+    $form['views_send_node']['views_send_node'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Send nodes of this content type using Views Send module.'),
+      '#default_value' => variable_get('views_send_node_'. $form['#node_type']->type, FALSE),
+    );
+    if (VIEWS_SEND_MIMEMAIL) {
+      $form['views_send_node']['views_send_node_preview'] = array(
+        '#type' => 'radios',
+        '#options' => array(
+            VIEWS_SEND_NODE_PREVIEW_TAB => t('As a tab on the node page'),
+            VIEWS_SEND_NODE_PREVIEW_IFRAME => t('As main node content'),    ¶
+          ),
+        '#title' => t('Preview'),
+        '#default_value' => variable_get('views_send_node_preview_'. $form['#node_type']->type, VIEWS_SEND_NODE_PREVIEW_IFRAME),
+      );
+    } ¶
+  }

@@ -995,6 +1306,81 @@ function _views_send_allow_php() {
+function views_send_node_get_types() {
+  $types = array();
+  foreach (content_types() as $type => $settings) {
+    if (variable_get('views_send_node_'. $type, FALSE)) {
+      $types[] = $type;
+    }
+  }
+  return $types;
+}
...
+  if ($types = views_send_node_get_types()) {

Just a discussion... Wouldn't be better to handle all setting in a single place? He always have "admin/settings/views_send". We can display there a multiselect list with content types and default test E-mail addresses (that can anyway be overwritten in the node form). In this case we can simplify by saving a single array variable for types variable_set('views_send_node_types', array('page', 'story;, ...)). Some functions will fall.

Powered by Dreditor.

ademarco’s picture

At DrupalCon CPH I had a discussion with Claudiu about refactoring this patch to be better integrated into the module's architecture.

One of the first things we must address is code duplication. The only changing part in the VBO email sending form is the email body: in case of n email message typed by the user it's a textarea, in case of a node sent by email it's a preview of such a node.

One approach could be to expose an hook (call it hook_views_send_message_info()) that would simply populate that part of the form depending on the action type ("send a node" or "send a message"). This implies that Drupal actions should be generated dynamically, something like what's already happening into VBO's ruleset.action.inc:

function views_bulk_operations_ruleset_action_info() {
  if (!module_exists('rules')) return array();
  $actions = array();
  foreach (rules_get_configured_items('rule_sets') as $ruleset_key => $ruleset) {
    if (count($ruleset['arguments']) == 1) { // For now, we only accept rulesets with one parameter (taken to be the 'type')
      $arg = key($ruleset['arguments']);
      $actions["views_bulk_operations_ruleset_action_{$ruleset_key}"] = array(
        'type' => $ruleset['arguments'][$arg]['type'],
        'parameters' => array('ruleset' => $ruleset_key),
        'description' => $ruleset['label'],
        'configurable' => FALSE,
        'rules_ignore' => TRUE,
      );
      eval(<<<EOS
if (!function_exists('views_bulk_operations_ruleset_action_{$ruleset_key}')) {
  function views_bulk_operations_ruleset_action_{$ruleset_key}(&\$object, \$context) {
    rules_invoke_rule_set(\$context['ruleset'], \$object);
  }
}
EOS
      );
    }
  }
  return $actions;
}

Using this approach Views Send would implement:

function views_send_views_send_message_info() {
  return array(
    'mail' => array(
      'description'       => t('Send mass mail'),
      'permissions'       => array('mass mailing with views_send'),
      'form callback'     => 'views_send_message_mail_form',
      'validate callback' => 'views_send_message_mail_validate',
    ),
    'node' => array(
      'description'       => t('Send content by E-mail'),
      'permissions'       => array('mass mailing with views_send'),
      'form callback'     => 'views_send_message_node_form',
    ),
  );
}

Views Send module will then dynamically generate Drupal actions. This would be interesting, for instance, in case a custom module would need to send a specific view:

function custom_module_views_send_message_info() {
  return array(
    'custom_view' => array(
      'description'       => t('Send my view by mail'),
      'form callback'     => 'custom_module_message_send_custom_view_form',
    ),
  );
}

What do you think? I will experiment in this direction and let you know.

claudiu.cristea’s picture

Yes. Let's go this way. This will make Views Send pluggable so we can create submodules like views_send_node or views_send_views and plug into VBO interface the right form elements, validation and processing.

Can you provide a patch in this direction? Thank you!

Aron Novak’s picture

It seems to be a really flexible approach, i'd love to see it in the module.

bsnodgrass’s picture

Love the direction this is going... Is there a patch available or has this been rolled into the dev version of views send yet? I would be glad to help test.

bob

benone’s picture

+1 for this what's happening here :)

also something like simplenews statistics to track how many users opened email and how many clicked any link inside it ... but it's a different story for later submodule...

THX for the patch Antonio!

kappaluppa’s picture

subscribing...

Marko B’s picture

Also subscribing and looking FWD.

hansfn’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)

No more development on the D6 version.