使用sendmail强制内容类型 [英] Force Content Type with sendmail

查看:74
本文介绍了使用sendmail强制内容类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用sendmail发送邮件时遇到了一个小问题:每封邮件都使用 Content-Type:multipart/alternative 发送,但是我想仅以 Content-Type:text发送邮件/plain .原因是因为GMAIL Web界面尊重RFC,所以我的消息以最新的 Content-type 显示,但是因为我的消息不是HTML格式,所以显示糟透了.

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.

我的bash脚本如下:

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

但是我的脚本似乎没有重写 Content-Type ,它仍然是 Content-type:multipart/alternative (根据 show original ).

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 :

  • output.txt中没有什么特别的(仅来自应用程序的日志行).
  • 我尝试了一个骇人听闻的破解:将< pre> </pre> 放在一起,但是& lt; pre&仍然无法显示邮件源中 Content-Type:text/html 部分...
  • 中的; gt;
  • 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...

如果您有任何线索,或者您知道如何使用sendmail更改 Content-Type 的顺序,请告诉我.

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

预先感谢

推荐答案

我有一个非解决方案,而不是强制我的邮件使用 text/plain ,我将以 text/html 发送邮件,但我将添加< pre> 标记以打开和关闭我的输出文件...因为它现在位于 text/html < pre> 标记不会显示为& lt; pre& gt;

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='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

这篇关于使用sendmail强制内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆