2

I am trying to send a mail with attachment and a subject line using unix's mail command but I get an error if I have both. If I only have a subject line it works, if I only have a attachment it works but not both. Anyone know how to do this?

data.out | mail -s "DATA" [email protected] < text.out

So this results in "Ambiguous input redirect"

1
  • 3
    What do you expect to happen if you say cat data | cat <other? Commented Apr 22, 2013 at 16:03

3 Answers 3

4

According to this article you can do what you want as:

(cat text.out; uuencode data.out data.out) | mail -s "DATA" [email protected]
Sign up to request clarification or add additional context in comments.

Comments

4

You're asking to send input from the data.out command into the mail command, as well as asking it to read from the file text.out; which is, to say the least ambiguous as the shell cannot do both.

If you want to get both the text and data into the mail message, then the easiest way to accomplish this is to do something like:

(cat text.out; data.out) | mail -s "DATA" [email protected]

now if data.out is a file rather than a command, then you can just do:

cat text.out data.out | mail -s "DATA" [email protected]

Comments

1

If it is available mutt works well for this as well as it directly supports attachments. I've found the mail program on some systems does not properly perform MIME encoding even if the attachment is piped in after being passed through uuencode.

An example of using mutt is:

echo "body text" | mutt -a attachment.txt -s "subject text" -- [email protected]

1 Comment

for some reason I could not attach files like mutt does it (7bit encoded) with mail or msmtp mail. mutt worked for me. Thanks. I would love to learn how to do it though. If anyone wants to reuse variables in ~/.muttrc, check this tutorial.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.