How to send mail with attachment from linux console

To send mail with attachment directly from your console, you can use utility mutt. This utility is not installed by default, so first we need to install it using the following command:

aptitude install -y mutt

Now you can run the following command to send the mail.

echo "Test mail" | mutt -a "/path/to/file/" -s "Mail backup" --

If you want to send mail with another senders address and From name, then use the following command:

echo "Test mail" | mutt -e "my_hdr From: Sender Name <>" -a /path/to/file/ -s "Mail backup" --

Lets take a look at what each of arguments do:

  • echo argument writes message body.
  • mutt argument calls the mutt command.
  • -e argument allows us to set senders address. This is modified using additional argument for mutt “my_hdr” (my header)
  • -a argument allows us to attach the file
  • -s argument uses to set message subject.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.