Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML and Inline Image duplicates body of email #160

Open
andrewrensburg opened this issue Oct 15, 2024 · 7 comments
Open

HTML and Inline Image duplicates body of email #160

andrewrensburg opened this issue Oct 15, 2024 · 7 comments

Comments

@andrewrensburg
Copy link

Hi,

When the mailmerge_template.txt looks like this:

TO: {{email}}
SUBJECT: {{broker}}
FROM: FooBar <[email protected]>
Content-Type: text/html
ATTACHMENT: {{attachment}}
ATTACHMENT: C:\Users\foobar\assets\latest_email_png.png

<html>
<body>

<p>Dear {{broker}},</p>

<p>Please find attached stuff.</p>

<p>Kind regards</p>
<p>The Stuff Team</p>
<img alt="second" src="C:\Users\foobar\assets\latest_email_png.png">

</body>
</html>

The body of the email is duplicated in the receiving mail.
Interestingly, the sent mail within Outlook doesn't look duplicated, but it is received duplicated:

Had to blackspace most of the image for confidentiality.

image

When removing the inline img tag, the bug no longer occurs.

@awdeorio
Copy link
Owner

Hmm, I'm having trouble duplicating the problem. Would you be able to make some very tiny version with dummy data?

@andrewrensburg
Copy link
Author

Sure thing!

Attached a mailmerge_database.csv with dummy data, the inline picture for testing, and a requirements.txt file if needed.

Requirements:
[requirements.txt](https://github.com/user-attachments/files/17395

Picture:
whatsapp
106/requirements.txt)

Database CSV:
mailmerge_database.csv
test.pdf

Mailmerge_template:
mailmerge_template.txt

You'll notice on the csv, I include both my active Outlook email and Gmail account for sending.
The one received on the 365 Outlook looks fine, no duplication, but gmail mail received duplicates the body of the mail.

Thanks for looking into this!

@awdeorio
Copy link
Owner

I tried to send a message using your template and database. Note that I modified some file paths. It looks like there's a problem with two email addresses separated by a semicolon.

My SMTP server returned an error:

failed to send message: {'': (501, b'Syntax violates RFC 5321 section 4.1.1.3:\n"RCPT TO:" ("<Postmaster@" domain ">" / "<Postmaster>" / Forward-Path ) [ SP Rcpt-parameters ] CRLF\nForward-path = Path\nPath = "<" [ A-d-l ":" ] Mailbox ">"')}

When the TO field contained just one email address, it worked for me. I wonder if that could be related to the problem? If your goal is for the message to end up in your own email archive, a trick is to include yourself as a BCC. If the goal is to send the same message to two people, a comma works (Don't forget to use quotes if this is in the CSV).

@andrewrensburg
Copy link
Author

Hi,

Very odd, both a semicolon and a comma works for me when sending to multiple addresses.

I've just tried both using the same database (one row of semicolon and another with comma), and both rows send (in effect, I receive two emails to the first address and two to the second address).

In production, where this 'bug' was identified, including myself as the first row in the CSV are for sanity checking purposes, whereas the rest of the rows are those correctly allocated, where 99% of the time there are multiple addresses separated by semicolon.

After this current test with a comma instead of semicolon, the body is still duplicated. Removing the inline image (removing the inline image attachment makes no difference) results in a single body.

Your tests have still not resulted in duplicated email body at all?

@awdeorio
Copy link
Owner

Your tests have still not resulted in duplicated email body at all?

Right.

Next idea: send one message where you expect to see a duplicate body. use mailmerge --output-format=raw and post the output. This will contain all the details of the message and attachment, so be sure to use dummy data!

@andrewrensburg
Copy link
Author

Thanks.

Output attached.
mailmerge-raw-output.txt

@awdeorio
Copy link
Owner

awdeorio commented Nov 14, 2024

I'm still have trouble replicating the problem. Here's what I've tried.

  1. Inspect the raw output you provided. It seems OK.

  2. Compare the raw output you provided to a sample message I constructed. They seem to be comparable.

TO: [email protected]
FRO: [email protected]
SUBJECT: Broker 1
Content-Type: text/html
ATTACHENT: test.pdf
ATTACHENT: whatsapp.jpg
Content-Type: text/html

<html><head /><body>

<p>Dear Broker 1,</p>

<p>Please find attached relevant documentation regarding stuff.</p>

<p>Kind regards</p>
<p>The Stuff Team</p>
<img alt="second" src="whatsapp.jpg" />


</body></html>
  1. Sent my simple message, works and looks OK.

Next steps

My next idea is to reduce the example to the smallest possible example where the problem still occurs and post it along with the mailmerge --output-format=raw output.

Can you remove some or all of the attachments (you mentioned this earlier)? One recipient? Inline image vs. attached?

Avoid using the database and just hardcode everything in the template. Use a dummy database that looks like this.

email
_

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants