If a single page request generates multiple emails which contain the same images (e.g. a common email header image), the image only appears in the first email generated.

e.g. I have a custom module which allows anonymous users to register for an event. This creates a user account (and therefore sends a registration email) and registers the user for the event (which sends an event registration email). Both emails should have a common header and footer image, but only the first email includes them.

CommentFileSizeAuthor
#2 mimemail-634210-2271220.patch292 bytesMark B
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Mark B’s picture

I've tracked this down to the _mimemail_file function in mimemail.inc

This function maintains two static arrays of referenced files which have been generated for the email being built:
$filenames = the names of the files which have been referenced and built
$files = the content of the files

When the email has been completely built, the function is called again, and the $files array is returned and cleared. However, the $filenames array is not cleared. This means that if a second email is built, the static $filenames array thinks that common files have already had their content built. However, their corresponding entry in $files has been cleared.

The solution is to clear the $filenames array at the same time as the $files array is cleared once the email has been completely built.

Mark B’s picture

FileSize
292 bytes

Patch file attached. Patch created against 6.x-1.0-alpha1, but bug exists in latest dev version too (which confusingly seems to be dated earlier than the 6.x-1.0-alpha1 release)

Mark B’s picture

Status: Active » Needs review
Czollli’s picture

Thanks, it works fine!

Czollli’s picture

Hi Mark,

I don't really understand the reason of array reinitialization
at the and, because these arrays marked static.
Before I have found your patch I removed the $files=array() line
and it also worked.
Or is it a special reason to do that?

Czollli

kurkuma’s picture

It works fine :-)

roball’s picture

Can someone please advise how to get an image (header logo) sent with the HTML mail? I'm using Simplenews together with Mime Mail, using the "html" Newsletter format. The HTML is generated using Wysiwyg API together with tinymce.

Thanks.

cafuego’s picture

@roball Use the simplenews_template module

cafuego’s picture

Speaking of simplenews_template, the patch attached above fixes the problem for images embedded in the node content, but seems to not fix the issue for images as defined in the simplenews_template header and footer.

In fact the header and footer images don't even get replaced with an inline Only local images are allowed. tag anymore, but just disappear after I apply this patch.

roball’s picture

Thanks cafuego! However, I can't get that module to work with the 2.x version of Simplenews - see #660662: Working with Simplenews 6.x-2.x-dev

cafuego’s picture

I'm not using simplenews 2.x-dev, but stable version 6.x-1.0.

roball’s picture

Priority: Critical » Normal
Status: Reviewed & tested by the community » Needs review

cafuego, sorry for the confusion - the additional fieldsets provided by Simplenews Template are now visible with Simplenews 6.x-2.x-dev.

Peter Bex’s picture

Priority: Normal » Critical
Status: Needs review » Reviewed & tested by the community

Please make a bugfix release (1.1), as this is a major problem with this module which should really not be allowed to exist for so long in a stable version.

acb’s picture

This is not fixing my problem; first mail gets sent with attachment intact; second gets sent with no attachment but the cid number below the mail.

cafuego’s picture

When I apply the patch, the attachments (and images) now work properly with simplenews 1.0

acb’s picture

Cafuego, some questions:

1) are your images in the body of the node?
(I have not tested w. attached images)

2) Are they absolute or relative URLs?
Absolute URls in the node work (as images are not embedded in emails) The relative URLs do not get embedded in newsletters after the first one.

cafuego’s picture

Priority: Normal » Critical
Status: Needs review » Reviewed & tested by the community

Hmm. why isn't my reply here.

@abc:

1) My images are in the body of the node and in the bodies of additional nodes I add via the related_content module.

2) The URLs are absolute from the site root. They do not include the entire !site_url as well.

acb’s picture

Right; if you use relative URLs you get the error, I think

bkonetzny’s picture

Resetting $filenames at the same time $files is reset in _mimemail_file() fixed the problem with missing files on batch e-mail operations. Thanks!

acb’s picture

could you post your code? Are you using relative or absolute URLs?

Are your files attached or are they in the body of the message?

sgabe’s picture

Status: Reviewed & tested by the community » Closed (duplicate)