I've created a patch that adds the ability to resend a logged mail. Mails that are a resend are not logged.

Comments

hargobind’s picture

Issue summary: View changes
StatusFileSize
new4.28 KB

Here's an updated patch against 6.x-1.x-dev. It also includes translation fixes, status message that the mail was sent, and a proper redirect to the current page being viewed.

hargobind’s picture

Version: 6.x-1.0 » 6.x-1.x-dev
hargobind’s picture

StatusFileSize
new5.16 KB

Fixed bug where subject and body were not being attached to the resent mail.

nancydru’s picture

Status: Active » Needs review
nancydru’s picture

Status: Needs review » Closed (outdated)
hargobind’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Closed (outdated) » Needs review
StatusFileSize
new6.27 KB

Here's a patch against 7.x that has been tested across 3 of my sites and is working great.

I have one concern though which is that the email's body is stored AFTER it has run through $mail_system->format() (line 89 of 7.x-1.4 or line 115 of this patch). And I think (but not positive) that $mail_system->format() is run AGAIN on the email body when the email is resent. All kinds of things could theoretically happen during $mail_system->format() if the site is using an alternate mail system including wrapping the body in a fancy HTML template, content replacement, etc. So the ideal scenario would be to store the email body as a serialized value and only call $mail_system->format() when viewing the email, but that's a bigger overhaul of the code than I'm willing do to right now. And, it would likely affect only a small percentage of sites that use this module, especially since most admins won't be using the "resend" feature except in fringe cases. But it's worth noting this in the readme.

nancydru’s picture

Yes, I agree that would be a better way to go.

hargobind’s picture

Status: Needs review » Needs work
StatusFileSize
new7.75 KB

Here's an updated patch based on the latest 1.x-dev and applies cleanly to 1.6.

I'm still not entirely satisfied with the functionality for stable use, but I'm making this patch available for anyone who wants it.

Two more things I want to eventually add (in addition to what was mentioned in comment #6: provide a confirmation screen before just resending the email, and adding the resend button to each individual mail log entry.

markusd1984’s picture

I installed mail logger mainly for the need to resend emails as the maillog module with their patch to add the resend button doesn't appear for me , it seems such simple yet powerful feature addition.

I tried mail logger and #8 but had to apply some of it manually for mail_logger.module

patching file mail_logger.module
Hunk #2 FAILED at 96.
1 out of 2 hunks FAILED -- saving rejects to file mail_logger.module.rej
patching file mail_logger.pages.inc
Hunk #2 succeeded at 76 with fuzz 2.
Hunk #3 succeeded at 102 (offset 4 lines).
Hunk #4 succeeded at 139 (offset 4 lines).

I tried the resend button several times but unfortunately, it doesn't send them again :(
Any way I can debug or check this?

Btw. great work @hargobind and great idea for a confirmation screen.
Ideally could be an indicator or even number count of 'resends' for tracking :)

markusd1984’s picture

I just realised due to #6 it might not work with HTML mail (+SMTP & mailsystem)?

I don't use theming and emails are sent and logged fine with mail logger.

If so, would be awesome if it can be integrated (I tried without HTML Mail, using just SMTP mail but also didn't resend) .
Resending emails is great for testing but also as quick and easy means to send them again to serve as a reminder to a user :)

markusd1984’s picture

Weird behaviour, I just disabled MIME Module and now the resend button worked.

BUT after I enabled MIME again I now have a much bigger issue as HTML Test emails are not being sent anymore :(

PDOException: in mail_logger_mail_alter() - mail_logger.module

last line of

db_insert('mail_logger')
        ->fields($record)
        ->execute();

When I disable mail logger with MIME active Test emails are still not being sent and I get error:

PDOException: in drupal_write_record() (/includes/common.inc).

Only once I disable MIME it's working again, hence I wonder if something broke or if the issue could be with MIME.

UPDATE: I had to re-install HTML MAIL for the Test Mails to work again.
I suspected that something got corrupted using the re-send patch and MIME module, maybe in the db.

markusd1984’s picture

I can confirm: resend is working when MIME is disabled - I can resend emails that were originally sent without MIME and also resend emails that where sent with MIME (were the text/plain alternative is then shown in the email body).

When MIME is enabled the resend doesn't work :(

SMTP: phpmailerException: Message body empty in PHPMailer->Send() (modules/smtp/smtp.phpmailer.inc).
SMTP: Error sending e-mail from test@example.com to test1@example.com : Message body empty
MAIL: Error sending e-mail (from test@example.com to test1@example.com).

Any chance you can look at this please, since it's not the mail systems the issue ?
I suspect that the mime part would have to be stripped for resend?

nancydru’s picture

All of my systems use Mimemail, so testing without may be difficult. An additional problem is that all the email handling systems think they should be the last to run and module weights are not sufficient to fix that. I had to install a custom hook_module_implements() to get Mimemail to run before SMTP, and Mail logger after both of them (it may not be the best, but it works). Specifically, #6 would be difficult to do in my situation.

markusd1984’s picture

Thanks, I haven't looked at MimeMail yet vs Mail Mime :)

Are you using this instead of the HTML Mail Module?

And because of your setup, you can't use the resend button at all?
If you can... is your mime part stripped out when resending emails (that had been sent with mime originally) ?

nancydru’s picture

We use MailSystem, MimeMail, and SMTP. I have not yet had the time to try this patch.