On the admin page, maillog_send can be turned on or off, yet this variable is never retrieved elsewhere in the code of this module (grep maillog_send . -R).

The result, in my experience, is that mail is never sent even if "Allow the e-mails to be sent." is checked on the page admin/config/development/maillog

If this can be verified, it is major.

Comments

dmartinc’s picture

Hello,
I am suffereing the same bug. I wanted the module to have a log of all mails sent by my site, but I do not want to block them.
Cheers,
David

itserich’s picture

Same problem. Log shows e-mail sent, but they are not received.

Disabled Maillog and e-mail is received again.

The only other mail module I have is Newsletter, so perhaps there is a conflict, but that is just a possible speculation. Newsletter has been working great for me on its own.

http://drupal.org/project/newsletter

ParisLiakos’s picture

Status: Active » Needs review
StatusFileSize
new3.67 KB

Can anyone check this patch?
i enabled sending of mails by using Drupal's default mail system

ParisLiakos’s picture

Ugh forgot a semicolon:/
stupid me.disregard the previous patch,use this instead

ParisLiakos’s picture

Priority: Major » Critical

And this is critical since it completely breaks the mail functionality all across the site

itserich’s picture

Thasnks rootatwc.

I applied the patch manually.

This is what now appears in maillog/includes/maillog.mail.inc

<?php

/**
 * An interface for pluggable mail back-ends.
 */
class MaillogMailSystem implements MailSystemInterface {
  /**
   * Format a message composed by drupal_mail() prior sending.
   *
   * @param $message
   *   A message array, as described in hook_mail_alter().
   *
   * @return
   *   The formatted $message.
   */
   public function format(array $message) {
     return DefaultMailSystem::format($message);
   }

  /**
   * Send a message composed by drupal_mail().
   *
   * @param $message
   *   Message array with at least the following elements:
   *   - id: A unique identifier of the e-mail type. Examples: 'contact_user_copy',
   *     'user_password_reset'.
   *   - to: The mail address or addresses where the message will be sent to.
   *     The formatting of this string must comply with RFC 2822. Some examples:
   *     - user@example.com
   *     - user@example.com, anotheruser@example.com
   *     - User <user@example.com>
   *     - User <user@example.com>, Another User <anotheruser@example.com>
   *    - subject: Subject of the e-mail to be sent. This must not contain any
   *      newline characters, or the mail may not be sent properly.
   *    - body: Message to be sent. Accepts both CRLF and LF line-endings.
   *      E-mail bodies must be wrapped. You can use drupal_wrap_mail() for
   *      smart plain text wrapping.
   *    - headers: Associative array containing all additional mail headers not
   *      defined by one of the other parameters.  PHP's mail() looks for Cc
   *      and Bcc headers and sends the mail to addresses in these headers too.
   *
   * @return
   *   TRUE if the mail was successfully accepted for delivery, otherwise FALSE.
   */
  public function mail(array $message) {
    // Log the e-mail
    if (variable_get('maillog_log', TRUE)) {
      $record = new stdClass;

      $record->header_message_id = isset($message['headers']['Message-ID']) ? $message['headers']['Message-ID'] : NULL;
      $record->subject = $message['subject'];
      $record->body = $message['body'];
      $record->header_from = isset($message['from']) ? $message['from'] : NULL;
      $record->header_to = isset($message['to']) ? $message['to'] : NULL;
      $record->header_reply_to = isset($message['headers']['Reply-To']) ? $message['headers']['Reply-To'] : '';
      $record->header_all = serialize($message['headers']);
      $record->sent_date = time();

      drupal_write_record('maillog', $record);
    }
   
    // Display the e-mail using Devel module
    if (variable_get('maillog_devel', TRUE) && function_exists('dpm')) {
      $devel_msg = array();
      $devel_msg[t('Subject')] = $message['subject'];
      $devel_msg[t('From')] = $message['from'];
      $devel_msg[t('To')] = $message['to'];
      $devel_msg[t('Reply-To')] = isset($message['reply_to']) ? $message['reply_to'] : NULL;
      $devel_msg[t('Header')] = $message['headers'];
      $devel_msg[t('Body')] = $message['body'];

      dpm($devel_msg, 'maillog');
    }
    if (variable_get('maillog_send', TRUE)) {
      $ret = DefaultMailSystem::mail($message);
    }
    else {
      $mail_warning = user_access('administer maillog') 
        ? t('Sending of e-mail messages is disabled by Maillog module. Go to @href to enable.', array('@href' => l('here', 'admin/settings/maillog'))) 
        : t('Drupal tried to send a mail. Note that mails are disabled currently.');

      drupal_set_message($mail_warning, 'warning', TRUE);
      $ret = TRUE;

    }
    return $ret;
    
   }

When I tried to send mail this error:

Parse error: syntax error, unexpected $end, expecting T_FUNCTION in /home/o32xzalq/public_html/sites/all/modules/maillog/includes/maillog.mail.inc on line 88

May have applied the patch incorrectly, did it manually.

ParisLiakos’s picture

yes you forgot a }.put it right in the end of the file

itserich’s picture

Title: Mail is never sent regardless of the value of the variable maillog_send » Maillog Indicates Mail Sent but Mail is never sent regardless of the value of the variable maillog_send

This is working for me now.

Thanks rootatwc!

ParisLiakos’s picture

Status: Needs review » Reviewed & tested by the community

Great!then i guess this is RTBC

jonathan_hunt’s picture

Patch at #4 solved the problem for me, thanks. It didn't apply with git apply, but patch -p0 worked.

miro_dietiker’s picture

Assigned: Unassigned » miro_dietiker

Uhh, need to review this. Thank you.

Curt44319’s picture

Applied the patch manually.
Tested as thoroughly as I can imagine.
Works perfectly.

berdir’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/includes/maillog.mail.inc
@@ -42,37 +42,48 @@ class MaillogMailSystem implements MailSystemInterface {
+    }
+    else {
+      $mail_warning = user_access('administer maillog') ¶
+        ? t('Sending of e-mail messages is disabled by Maillog module. Go to @href to enable.', array('@href' => l('here', 'admin/settings/maillog'))) ¶
+        : t('Drupal tried to send a mail. Note that mails are disabled currently.');
+
+      drupal_set_message($mail_warning, 'warning', TRUE);
+      $ret = TRUE;
+
+    }

Some trailing whitespaces here, which can be removed with git apply --whitespace=fix when the patch is applied.

Not sure about these messages. Maybe make that configurable as well so that you can disable displaying them. And they could probably be reworded a bit, especially the one without the link. Using Drupal in user facing text should be avoided. Maybe something like "Sending mails is currently disabled.".

Also, the path there is wrong, that's the Drupal 6 style of configuration links. If the maillog settings are really at that location, then that needs to be fixed.

ParisLiakos’s picture

Status: Needs work » Needs review
StatusFileSize
new3.79 KB

Thanks for the corrections Berdir.
i believe this is better now.used watchdog for non-adminstrators

ParisLiakos’s picture

meh disregard #14

ParisLiakos’s picture

One more improvement, swapped time() with REQUEST_TIME

berdir’s picture

Status: Needs review » Needs work
+++ b/includes/maillog.mail.inc
@@ -14,7 +14,7 @@ class MaillogMailSystem implements MailSystemInterface {
    public function format(array $message) {
-     return $message;
+     return DefaultMailSystem::format($message);
    }

Hm, I'm surprised that this actually works?

The format and mail methods of DefaultMailSystem aren't declared as static, so it shouldn't be possible to call them without having an actual object instance.

One way to solve this would be to extend MailLogMailSystem from the DefaultMailSystem class and then call parent::format($message) (which looks like a static call as well, but actually isn't).

The downside of this is that it is hardcoded to the default system (as is your code too) but it looks like e.g. devel.module is doing the same thing.

Alternatively, you could do this:

$default = new DefaultMailSystem();
return $default->format($message);

Then we could still make this configurable at some point, if someone needs it (e.g. to send mime mails or through smtp).

ParisLiakos’s picture

doh...they are not static indeed..
i am as suprised you are...didnt know that calling a public function this way, actually works:/
the docs confused me:P
saw this page http://api.drupal.org/api/drupal/modules--system--system.mail.inc/class/... and :: made me think that its methods are static...

ParisLiakos’s picture

Status: Needs work » Needs review
StatusFileSize
new3.98 KB

ok here it is

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Manually tested that this patch works correctly.

miro_dietiker’s picture

Status: Reviewed & tested by the community » Fixed

Thank you, guys.
Committed, pushed.
Fixed, was D7 only. No backport needed.

Status: Fixed » Closed (fixed)

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