DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Mail A File As An Attachment From The UNIX Prompt

  • submit to reddit
uuencode file.txt file.txt | mail


Snippets Manager replied on Fri, 2007/04/13 - 10:44am

If you have mutt installed, you can send mail as follows: mutt -s "This a subject" \ -a Attached_File.txt \ < Email_Body.txt With mutt, you can add many attachments (not sure if there is a limit) and you don't have to mess with uuencode and mailx. Attachments are attached as one would expect. This functionality can be wrapped easily in a script that so that you can make use of environment/script variables for the arguments.

Snippets Manager replied on Mon, 2012/05/07 - 1:14pm

If you prefer to use MIME, mime-construct can be used: mime-construct \ --to "" \ --subject "Your computer" \ --string "Your computer is on fire" \ --type text/plain --file-attach extinguishing_howto.txt