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

08.21.2005
| 28913 views |
  • submit to reddit
        
uuencode file.txt file.txt | mail email@address.com
    

Comments

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 \ recipient@email.com < 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 "person@example.com" \ --subject "Your computer" \ --string "Your computer is on fire" \ --type text/plain --file-attach extinguishing_howto.txt