How would I use the mail command, without the mutt utility, to send a tar.gz file. The Mail utility works on the command line, however it asks me who to cc and the text on the terminal page. It also requires me to ctr D to send a mail. How would I avoid this in a script?


This question has sort of been answered already...


Based on the answers I've seen above though it doesn't deal with the CC part though. Basically, you just need to add a "-c ccaddress@emailaddress.com" option.

cat message.txt | mail -s "Backup" -a file.tar.gz backup@email.com -c ccaddress@emailaddress.com

Stick it in a script file and it that will be the basis for further automation.

  • I may be reading the question wrong, but it sounds like they don't want to fill out the CC field at all. – Grayson Kent Jun 7 '17 at 13:23

You cat some sort of message file to the mail utility.

cat mailbody.txt | mail -A yourfile.tgz -s "your mail subj line" email@to.send.to

Note that contrary to previous answer at least in Ubuntu mail utility you specify attachments by -A. -a is used to add extra headers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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