Search code examples
shellsendmailcentos6postfix-mta

Centos 6 /usr/sbin/sendmail - how to send email with subject?


Trying to send an email from shell (Centos 6) using one line command, but subject is empty

echo 'body' | /usr/sbin/sendmail [email protected] Subject:"Test Send Mail"

Spent hours trying googling and find an answer how to send email using "/usr/sbin/sendmail" with subject, but no matter what I try, subject is empty.


Solution

  • (echo "Subject: Test"; echo; echo 'body')|/usr/sbin/sendmail -i [email protected]

    Or cleaner script version

    #!/bin/sh
    /usr/sbin/sendmail -i [email protected] <<END
    Subject: Test
    
    body
    END
    

    WARNINGS:

    1. Non US-ASCII characters require special encoding in headers and custom headers when included in body.
    2. Keep subject (header) in single text line
      [header continuation lines must start with space or tab]
    3. Sendmail breaks too long text lines (990 bytes)