1

i want to reproduce a mail related problem regarding a mail that is sent from a system i have no control over. For this purpose i want to mimic this problematic email.

I have the exact mail as it was received as a text file (headers + base64 encoded body) How can i send a very similar mail from one of our systems?

I tried

mail -s "Test" [email protected] < mail.txt

But it puts the whole text file into the body.

thanks in advance Jens

Jens Kisters
  • 49
  • 1
  • 7

2 Answers2

0

According to RFC 5322 Internet Message Format the body of the message starts after an empty line.

You can use awk to print everything in mail.txt after the first empty line, like this:

awk '/^$/,0' mail.txt

So you could do something like

awk '/^$/,0' mail.txt | mail -s "Test" [email protected]

That, however, will start the output with an empty line. If you want to avoid that, use a slightly more complicated awk range:

awk 'p; !/./{p=0}/^$/{p=1}' mail.txt | mail -s "Test" [email protected]

This last trick is one I picked up here.

Jos
  • 28,156
  • 8
  • 82
  • 88
0

If the machine has the sendmail compatibility program installed (usually it should have it, this was tested with postfix installed), then you can use a command like this:

sendmail -i -f [email protected] [email protected] <test.mail

With test.mail looking like this for example:

From: [email protected]
To: [email protected]
Subject: Test
X-Spam-Flag: NO

some content

You will most likely not be able to reproduce too much of the original email, since many headers are only added or modified later by the mail server itself.

Sebastian Stark
  • 6,052
  • 17
  • 47