E-mail Attachment | Ubuntu Command Line | Howto

Here is a very usefull command on sending files as attachement on Linux/Unix command line, this is specifically very usefull when using it in script to send daily report, or just for mailing client certificate directly from the server, there are two ways I know that you can use to send a file as attchemnt using command line, one is using uuencode utility with the "mail" command and the other one using "mutt", I find using mutt command to be much more reliable compared to using uuencodeutility with mail command.

uuencode utility writes an encoded version of the named input file, or standard input if no file is specified, to standard output. The output is encoded using the algorithm described in the STDOUT section and includes the file access permission bits of the input file and the decode_pathname, for re-creation of the file on another system that conforms to this specification.

If you don't have uuencode command on your system, and your running Cent OS or Redhat distribution you can find the uuencode and uudecode on the “sharutils" package.

To send a file attachment using "mail" command
$ uuencode filename.jpg filename.jpg | mail -s 'subject' recipient@email.com

To send a file attachemnt using "mutt" command
$ echo | mutt -a filename.jpg -s 'subject' recipient@email.com

Mutt is a small but very powerful text based program forreading electronic mail under unix operating systems,including support color terminals, MIME, and a threadedsorting mode.


0 comments:

Post a Comment