How to send a mail with attachment directly from console

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

aptitude install -y mutt

For installation on CentOS, use the following command

yum install mutt

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

echo \"Test mail\" | mutt -a \"/path/to/file/file.zip\" -s \"Mail backup\" -- alias@domain.com

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

echo \"Test mail\" | mutt -e \"my_hdr From: Sender Name <sender@domain.com>\" -a /path/to/file/file.zip -s \"Mail backup\" -- alias@domain.com

Let us take a look at what each of the arguments do:\n

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

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