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" me@nowhere.net < mail.txt

But it puts the whole text file into the body.

thanks in advance Jens

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" me@nowhere.net

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" me@nowhere.net

This last trick is one I picked up here.

  • @SebastianStark I may have, yes. I did not test the full command. – Jos Jul 18 '18 at 13:48
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 from@example.org to@example.org <test.mail

With test.mail looking like this for example:

From: from@example.org
To: to@example.org
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.