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:
<pre> and </pre> but the display is still awful with <pre> 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
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 <pre>
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
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[@]}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With