I am running Simplenews 6.x-2.0-alpha2 with current MIME Mail module on Drupal 6.22.

Sending both test newsletters directly with PHP and real newsletters via cron works. If a user tries to subscribe to a newsletter (double opt-in), however, no email is being send. Furthermore no email address is stored (but maybe that's because no confirmation link was called yet?). Permission for anonymous users to subscribe was granted.

So as sending newsletters to already subscribed users works, there must be some issue inside Simplenews why confirmation emails are not triggered. Any suggestions?

Comments

simon georges’s picture

Is the unsubscribe mail triggered when a subscribed user wants to opt out?

Actron’s picture

No, neither subscribe nor unsubscribe emails are being sent, when double opt-in is activated. I can only send test and real newsletters.

By the way: There is no unsubscribe button in Simplenews' single sign-up block, which is very uncomfortable.

Actron’s picture

Priority: Normal » Major

Changing priority to major, because guest user cannot subscribe to newsletters.

simon georges’s picture

Are standard Drupal mail (register, and so on) being sent? Can you try when deactivating MimeMail?

Actron’s picture

Tried without MIME Mail, but did not change anything. All other emails are being sent, except for opt-in/opt-out messages.

When I confirm the subscribe form, I even get a message that tells me to check my emails for confirmation. Do users already show up in the subscriber manager, when confirmation is pending? Because there is no new enty, too. So it seems there is nothing taking place in the background, when hitting the submit button.

Actron’s picture

Can I add debug output somewhere to provide you with further information or to see what code is reached? Any other ideas how I can solve my problem?

simon georges’s picture

I know that Mail log module exists, but as your problem is an absence of mail, I'm not completely sure it will be useful... The best way to trace what's happening would be using a debugger like XDebug...

Actron’s picture

Can't I just simply add echo() to the source files somewhere? I'm not that much into Drupal development yet.

simon georges’s picture

It's normal that users don't show up in the subscription manager if they haven't confirmed.
But the mails should be sent... Could the mail be in the Spam folder of your client, by any chance?

Actron’s picture

OK, thanks for clarification about the subscription manager.

No, there are no spam filters involved (at least non that I know of). I also checked with different email addresses from various providers, but the problem is the same everywhere.

Does Simplenews use the same mailing mechanism for confirmation messages and test newsletters? So to say that when one of it works, the other should work, too? That's what confuses me right now, since everything works except for the confirmation mails.

Actron’s picture

Status: Active » Patch (to be ported)

OK, I think I figured out what's wrong. Attached you find some code that fixed the problem for me. You may use it to patch Simplenews 6.x-2.0 if you feel like this could be a general solution.

But let me explain what I did first: I added some debug output to the code that sends the test newsletters and that sends the subscription emails. Then I quickly realized that the test letter code (which worked) was different from the subscription one (which did not work). The test letter method uses mimemail to send emails, while the subscriptions are solely sent through the Drupal email backend.

As soon as I changed the code such, that subscription emails are send with mimemail as well (if module is installed), it worked for me. I guess the fallback mechanism (Drupals mail backend) will still not work on my server, but that seems to be related with the server environment. There was a message in the logs "Sender address rejected", because Drupal tried to send the email from wwwrun@domain.tld (where wwwrun is the webserver's user name) and that address did not exist.

Anyway, here is my patch: Open 'simplenews.module' and change the code that sends the subscription mails as following (remove the old call of drupal_mail() and replace it with the block of code that is marked with FIXME). The solution code was taken from the one Simplenews method that sends the test newsletters.

...

  if ($confirm) {
    module_load_include('inc', 'simplenews', 'includes/simplenews.mail');
    // Send confirmation email to user to complete subscription or to tell
    // them that he or she is already subscribed.
    // Confirmation mail is in the user preferred language which is by default the language_default().
    $params['from'] = _simplenews_set_from();
    $params['context']['newsletter'] = taxonomy_get_term($tid);
    $params['context']['account'] = $subscription;

    // FIXME: Block begin

    // Send mail
    if (module_exists('mimemail')) {
      // If mimemail module is installed ALL emails are send via this module.
      // drupal_mail() builds the content of the email but does NOT send.
      $message = drupal_mail('simplenews', 'subscribe', $mail, $subscription->language, $params, $params['from']['address'], FALSE);
      $to = isset($message['params']['context']['account']) ? $message['params']['context']['account'] : $message['to'];
      $plain = $message['params']['context']['node']->simplenews['s_format'] == 'plain' ? TRUE : NULL;
      $mimemail_result = mimemail(
        $message['from'],
        $to,
        $message['subject'],
        $message['body'],
        $plain,
        $message['headers'],
        $plain ? $message['body'] : simplenews_html_to_text($message['body'], TRUE),
        isset($message['params']['context']['node']->files) ? $message['params']['context']['node']->files : array(),
        $message['id']
      );
      // Mimemail has changed its API (see http://drupal.org/node/808518) but we keep backward compatibility
      if (is_array($mimemail_result)) {
        $message = $mimemail_result;
      } else {
        $message['result'] = $mimemail_result;
      }
    }
    else {
      $message = drupal_mail('simplenews', 'subscribe', $mail, $subscription->language, $params, $params['from']['address'], TRUE);
    }

    // FIXME: Block end

  }
  elseif (!isset($subscription->tids[$tid])) {
    // Add user to newsletter relationship if not already subscribed.

    // Check if user is (un)subscribed to this newsletter.
    // Resubscribe or add new subscription.
    if (isset($subscription->newsletter_subscription[$tid])) {

...

Hope that helps.

simon georges’s picture

Status: Patch (to be ported) » Needs review
Actron’s picture

Just noticed that the same fix has to be applied to simplenews_unsubscribe_user() method for unsubscribe messages. The code is the same, except that 'subscribe' must be replaced with 'unsubscribe' when calling drupal_mail() (in if and else part).

simon georges’s picture

Version: 6.x-2.0-alpha2 » 6.x-2.x-dev
Status: Needs review » Active

Would you be willing to submit a proper patch?

Actron’s picture

StatusFileSize
new6.07 KB

Haven't done that before. Attached you'll find a patch that I created with git. Hope that helps.

berdir’s picture

Huh?

I can see that similar code already exists in simplenews and that's probably where you've copied it from, but this feels very weird to me.

Looking at mimemail.module 6.x-1.0 (from november, so quite new), it contains the drupal_mail_wrapper() function, which is defined like this:

 /*
 * Overrides Drupal's default mail sending process.
 */
if (strpos(variable_get('smtp_library', ''), 'mimemail') !== FALSE
  && !function_exists('drupal_mail_wrapper')) {

  function drupal_mail_wrapper(&$message) {
    $from = $message['from'];
    $to = $message['to'];
    $subject = $message['subject'];

    if (preg_match('/plain/', $message['headers']['Content-Type'])) {
      $format = variable_get('mimemail_format', FILTER_FORMAT_DEFAULT);
      $body = check_markup($message['body'], $format, FALSE);
    }
    else {
      $body = $message['body'];
    }

    $plaintext = isset($message['plaintext']) ? $message['plaintext'] : NULL;
    $headers = isset($message['headers']) ? $message['headers'] : array();
    $text =  isset($message['text']) ? $message['text'] : NULL;
    $attachments = isset($message['attachments']) ? $message['attachments'] : array();
    $mailkey = isset($message['id']) ? $message['id'] : '';

    $message = mimemail($from, $to, $subject, $body, $plaintext, $headers, $text, $attachments, $mailkey);

    return $message['result'];
  }
}

Why can't we rely on that?

And if we really need to call mimemail() directly (what about other mail sending modules?), we should *at least* have our own api function to do this then instead of copy & pasting the code.

Actron’s picture

Yeah, you are probably right about having a single function with that code.

Actron’s picture

StatusFileSize
new7.54 KB

Refactored. Please check if this works for you.

Actron’s picture

Status: Active » Patch (to be ported)
simon georges’s picture

Status: Patch (to be ported) » Needs review
Actron’s picture

Is there any progress in reviewing?

Status: Needs review » Needs work

The last submitted patch, subscription_emails_r2.patch, failed testing.

miro_dietiker’s picture

Issue summary: View changes
Status: Needs work » Closed (won't fix)

Closing old support requests.