Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force Content Type with sendmail

I got a little problem when sending mail with sendmail: each mail are sent with Content-Type: multipart/alternative but I wonder to send my mail only in Content-Type: text/plain. The reason is because of GMAIL web interface respect the RFC, my message is displayed with the latest Content-type but because my message is not in HTML, the display is awful.

My bash script is as following:

#!/bin/bash

SENDMAIL_BIN='/usr/sbin/sendmail'
FROM_MAIL_ADDRESS='[email protected]'
FROM_MAIL_DISLAY='Test format mail'
RECIPIENT_ADDRESSES='[email protected]'

MAIL_CMD="$SENDMAIL_BIN -f $FROM_MAIL_ADDRESS -F \"$FROM_MAIL_DISLAY\" $RECIPIENT_ADDRESSES"
(echo "Subject: Test format";echo -e "MIME-Version: 1.0\nContent-Type: text/plain;\n\n" && cat output.txt) | eval $MAIL_CMD

But my script doesn't seem to rewrite the Content-Type and it's still Content-type: multipart/alternative (according to the show original of my mail).

nota:

  • There is nothing special in my output.txt (only log lines from my app).
  • I tried a gruik hack: put a <pre> and </pre> but the display is still awful with &lt;pre&gt; in the source of the mail in the Content-Type: text/html part...

If you have any clue or if you know how to change the order of the Content-Type with sendmail let me know.

Thanks in advance

like image 461
Labynocle Avatar asked Dec 13 '25 03:12

Labynocle


2 Answers

I have a non solution, instead of to force my mail to be in text/plain, I will send a mail in text/html but I will add the <pre> tag to open and close my output file... And because it's now in text/html, the <pre> tag is not displayed as &lt;pre&gt;

It's not what I excepted but it works. So my previous script simply become:

#!/bin/bash

SENDMAIL_BIN='/usr/sbin/sendmail'
FROM_MAIL_ADDRESS='[email protected]'
FROM_MAIL_DISLAY='Test format mail'
RECIPIENT_ADDRESSES='[email protected]'

MAIL_CMD="$SENDMAIL_BIN -f $FROM_MAIL_ADDRESS -F \"$FROM_MAIL_DISLAY\" $RECIPIENT_ADDRESSES"
(echo "Subject: Test format";echo -e "MIME-Version: 1.0\nContent-Type: text/html;\n" && echo '<pre>' && cat output.txt && echo '</pre>') | eval $MAIL_CMD
like image 91
Labynocle Avatar answered Dec 14 '25 18:12

Labynocle


Try removing the extra semicolon on the content type:

echo -e "MIME-Version: 1.0\nContent-Type: text/plain\n\n"

Also it's better to use arrays than parse a string with eval:

#!/bin/bash

SENDMAIL_BIN='/usr/sbin/sendmail'
FROM_MAIL_ADDRESS='[email protected]'
FROM_MAIL_DISLAY='Test format mail'
RECIPIENT_ADDRESSES='[email protected]'

MAIL_CMD=("$SENDMAIL_BIN" -f "$FROM_MAIL_ADDRESS" -F "$FROM_MAIL_DISLAY" "$RECIPIENT_ADDRESSES")
(echo "Subject: Test format";echo -e "MIME-Version: 1.0\nContent-Type: text/plain\n\n" && cat output.txt) | "${MAIL_CMD[@]}"
like image 28
konsolebox Avatar answered Dec 14 '25 20:12

konsolebox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!