0

How can I format a file so I can just do cat file | sendmail?

By putting Subject: This is the subject, I don't need to specify the subject in sendmail, but adding the To: [email protected] field gives me Recipient names must be specified

2 Answers 2

2

You are missing the distinction between message contents (headers and body) and message envelope. You're invoking sendmail with message contents, but you aren't supplying the envelope. It's the envelope that controls delivery. Without it, the message cannot go anywhere.

You don't say which sendmail command that you are using. Each MTS — Sendmail, qmail, Postfix, exim, and so forth — has its own. The common subset of them all has just two ways of specifying envelope sender and envelope recipients:

  • explicitly on the command line as arguments to sendmail:
    < file sendmail -f [email protected] postmaster@localhost
  • implicitly in the message body, which is parsed for To:, Cc:, and Bcc: headers:
    < file sendmail -f [email protected] -t

This common subset is very limited. Observe, for example, that this mode of message submission from standard input and command arguments is Sendmail's -bm mode, but not all sendmail programs actually even support a -bm option. So to portably invoke this mode, you cannot use the option.

There are also portability caveats when combining -t with recipients given as command arguments, for the details of which see Dave Sill's book. So pick one form or the other. Don't mix them.

Further reading

  • Dave Sill (2001). "sendmail injection". The qmail Handbook. ISBN 9781893115408. Apress. pp. 123–126.
  • Weitse Venema. sendmail. Postfix manual pages.
  • sendmail. Courier manual pages.
  • Era Eriksson (2000). The Useless Use of cat Award.
1

By default, sendmail expects the recipients to be specified on command line. Use -t to make it read the To:, Cc:, Bcc: headers.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .