Sending Email With Attachments From The Command Line

| 4 Comments
It's often handy to send email from the command line using mail, however it isn't very obvious how to attach files to the resulting email. To do it, you just require uuencode. In both Debian and Red Hat based distributions, this will be in the sharutils package. To send attachment with the email run the following command:
(echo Email Body Text; uuencode ~/file1.zip file1.zip;) | mail -s "Email Subject" recipient@example.com
This will attach file1.zip to the email and send it to recipient@example.com.

4 Comments

Thunderbird picks up the attachment nicely. Pine or Mutt doesn't :-/

Steve,

Hadn't tried sending uuencoded messages to them before. However there is a way around it using mpack.

mpack -s "Subject" -d file.with.body -c application/octet-stream file.to.attach recipient@example.com

Cool. Cheers for the tip.

If mutt is configured, you can just:

echo 'The files are attached' | mutt -a filename -s 'Subject text here' recipient@example.com

About this Entry

This page contains a single entry by Niall Donegan published on April 24, 2007 1:46 PM.

Why Excel Ends Up Being Used As A Database was the previous entry in this blog.

Carlow Municipal Wifi Network is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Pages

OpenID accepted here Learn more about OpenID
Creative Commons License
This blog is licensed under a Creative Commons License.
Powered by Movable Type 5.02