从sendmail发送带有标题的电子邮件

我正在尝试使用sendmail发送电子邮件,但是我需要指定一些标题(From,Content-Type,Subject)。 这是我目前正在运行的命令:

echo“Content-Type:text / plain \ r \ n来自:[email protected] \ r \ n主题:testing\ r \ n \ r \ n身体在这里”| sendmail -f [email protected] [email protected]

问题是头没有被设置。 我的格式是否正确?

你需要用'e'参数使用echo

  -e  
    在每个STRING中启用对以下反斜线转义字符的解释:  
       \ n新行  
       \ r回车 

如果你看看你的命令发送邮件的结果,你会看到以下内容:

 Content-Type: text/plain\r\nFrom: [email protected]\r\nSubject: Test\r\n\r\nThe body goes here 

(从字面上看,就像上面的一行一样,包括“特殊字符”)

应用上面的,轻微的修改允许你的代码工作正常:

 echo -e "Content-Type: text/plain\r\nFrom: [email protected]\r\nSubject: Test\r\n\r\nThe body goes here" | sendmail -f [email protected] [email protected]