Avatar (Fabio Alessandro Locati|Fale)'s blog

How to send an e-mail with attachment from the command line

January 3, 2013

Have you ever had to develop a script in UNIX that has to send an email?

If you have, probably you have used the “mail” function since this program is the standard program to send e-mails in UNIX environments if you are using the CLI (Command Line Interface).

The manual for mail reports this as mail usage prototype:

mail -r [sender] -s [subject] receiver-1[,receiver-2,...,receiver-n] > [File with the body]

I think all the parameters are pretty straightforward except the “File with the body” one. This has to be an ASCII file (ie: .txt) with the e-mail body content in the text-only mode.

Read More