问题
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='noreply@plop.com'
FROM_MAIL_DISLAY='Test format mail'
RECIPIENT_ADDRESSES='me@plop.com'
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<pre>
in the source of the mail in theContent-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
回答1:
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='noreply@plop.com'
FROM_MAIL_DISLAY='Test format mail'
RECIPIENT_ADDRESSES='me@plop.com'
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
回答2:
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='noreply@plop.com'
FROM_MAIL_DISLAY='Test format mail'
RECIPIENT_ADDRESSES='me@plop.com'
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[@]}"
来源:https://stackoverflow.com/questions/18233696/force-content-type-with-sendmail