Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to send an e-mail with sendmail, but I need to specify some headers (From, Content-Type, Subject). Here is the command I am currently running:

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

The problem is that the headers are not being set. Do I have the format correct?

share|improve this question
up vote 4 down vote accepted

You need to use echo with the 'e' parameter.

    Enable interpretation of the following backslash-escaped characters in each STRING:  
      \n          new line  
      \r          carriage return

If you look at the result of sending mail with your command you see the following:

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

(It literally shows up as above as a single line, including the 'special characters')

Applying the above, slight, modification allows your code to work fine:

echo -e "Content-Type: text/plain\r\nFrom:\r\nSubject: Test\r\n\r\nThe body goes here" | sendmail -f
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.