Sending email through command line with Mutt

12 / Sep / 2012 by Abhishek Tejpaul 0 comments

In one of the shell scripts I was reading I saw a usage of mutt text-based command line email client. Mutt can be used to send out the emails from the production machines or any other servers where you do not have access to the browsers or UI based email clients. Sometimes it is essential to send out a particular log file to certain people for bug fixing while you are checking on the prod machine.

Here is how you can send out the emails from the Linux (at-least for most of the Debian based distributions such as Ubuntu)

  sudo apt-get install mutt

Now you can type in the following command:

 mutt -s <emailSubject> <recipientEmail> -c <ccRecipientEmail> -b <bccRecipientEmail> -a </path/to/the/attachmentFile> < </path/to/the/fileContainingTheMessage>

We can see an example here:

 mutt -s "Demo Subject Line" xyz@xyz.com -c abc@xyz.com -b blind-recipient@xyz.com -a /tmp/meetingDetails.xls < /tmp/emailBody.txt

As you can see, the -s flag is used to specify the subject line of the email and the optional flags -c and -b are used to specify the “cc” recipient and “bcc” recipient respectively. Also, -a flag is used to specify the location of the attachment file. There is one caveat regarding the -a flag i.e. -a option must be placed at the end of command line options. You can read the mutt documentation for more information on this.

This utility is a nice to know tool if you are a developer working in Linux and can use it in shell scripts whenever there is an apt use-case. You can read more about mutt and other cool things or by typing the ‘man mutt‘ command in your terminal.

Hope this helps !!

FOUND THIS USEFUL? SHARE IT

Leave a comment -