Hi
I'm using HtmlMail with Simplenews and Echo. My Newsletter content type has, in addition to title and body fields, Signature, Date, Category and Attachment fields.
When I send the newsletter, no HTMLMail theming is applied to the Date, Category and Attachment themes. They all run together in small font at the bottom of the page (I figured out that this come from the Simplenews footer template). I want them to get HtmlMail theming.

I have included a fields--field_name.tpl file for them in my theme templates folder and cleared my caches, with no effect. The newsletter has the correct theming for these fields when viewd on the website but this does not come through in the email.

Interestingly the Signature field is appearing correctly on both the page and the email. But this field is a node reference field in the content type.

Any ideas on what I should do? AT this point I'm willing to dig into php though I'm not a coder.

emk

Comments

pillarsdotnet’s picture

Title: How does HTML Mail render a Simplenews newsletter message? » Support theming additional fields
Component: Module compatibility » Code

The mail is not sent by rendering the simplenews newsletter page.

Here is the actual chain of events:

  1. simplenews_send_node() associates the newsletter node id with a list of recipient subscriber ids, and adds them to the simplenews_mail_spool table.
  2. simplenews_mail_spool() retrieves the list, switches to the anonymous user, and initiates sending of each newsletter/recipient combination.
  3. simplenews_mail_mail() loads the node object, adds newsletter context, and calls drupal_mail() to send the message.
  4. After adding some default headers, drupal_mail() calls simplenews_mail() to apply module-specific formatting.
  5. simplenews_mail() calls simplenews_build_node_mail()
  6. If the Translation module is enabled, translation_node_get_translations() attempts to fetch a node in the recipient's preferred language. Otherwise, node_load() is used.
  7. _simplenews_headers() adds Simplenews-specific headers to the message.
  8. node_view($node, 'email_plain') converts the node object to a FAPI render array.
  9. The simplenews_field theme key is applied to each field in the render array.
  10. theme('simplenews_newsletter_body', ...) converts the render array to HTML message body text.
  11. theme('simplenews_newsletter_footer', ...) converts the same render array to HTML message footer text.
  12. If plaintext output is selected, simplenews_html_to_text() converts the message body from HTML to plaintext.
  13. drupal_mail() calls HTMLMailSystem::format() to format the message.
  14. If the Mail MIME module is enabled, HTMLMailSystem::formatMailMIME() uses the MailMIME class functions to parse the message body into MIME parts, convert referenced images into inline attachments, and extract the text/html message part.
  15. theme('htmlmail', $message) applies the htmlmail--simplenews.tpl.php template to add custom theming.
  16. mailsystem_html_to_text creates a plaintext alternative to the templated output.
  17. If the Echo module is enabled, the echo_themed_page() passes the message body, title, and theme as POST arguments to drupal_http_request(), which loads the url('echo') page to wrap the themed, templated message body in a mail-specific themed page.
  18. If a post-filter is selected, check_markup() applies it to the themed, templated, wrapped message body. This is where the the Emogrifier module may be used to convert CSS stylesheets to inline style attributes.
  19. drupal_mail() passes the themed, templated, wrapped, and converted message to HTMLMailSystem::mail(), which passes the message recipient, subject, body, and headers to the PHP mail() function to send the message.

There are lots of places in there where theme callbacks, templates, and overrides can add extra information, but I assure you that the HTML Mail module is not ignoring any of the information made available to it by Simplenews.

Your confusion probably arises because in step 8 above, the email_plain view sent by email differs from the full view shown on the webpage.

If the extra information you desire to include is available in the loaded node object, your best solution is probably to copy the htmlmail.tpl.php and htmlmail--simplenews.tpl.php to your mail-specific theme directory, and edit the copied htmlmail--simplenews.tpl.php template to reference the $params['node'] and insert the field information as you see fit.

If the extra information you desire is available as a block, simply add it to your mail-specific theme by visiting admin/structure/blocks.

Other solutions include:

Let me know if you need more information/guidance/suggestions/help.

pillarsdotnet’s picture

Title: Support theming additional fields » How does HTML Mail render a Simplenews newsletter message?
Component: Code » Module compatibility
Status: Active » Postponed (maintainer needs more info)
pillarsdotnet’s picture

Title: Support theming additional fields » How does HTML Mail render a Simplenews newsletter message?
Component: Code » Module compatibility
Assigned: Unassigned » pillarsdotnet
Status: Postponed (maintainer needs more info) » Fixed

Copied the above to a documentation page and linked from the README in the 7.x-2.61 release.

blasthaus’s picture

this is incredibly helpful, thanks huge for this post!

Status: Fixed » Closed (fixed)

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

Maciej Lukianski’s picture

Thanks for this great post! It really helped me.

I just wanted to add that the node object sits in $params['context']['node']

fanton’s picture

Issue summary: View changes

I get the node object with $params['simplenews_source']->getNode(); in version 7.x-2.65