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/file.zip" -s "Mail backup" -- alias@domain.com
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 <sender@domain.com>" -a /path/to/file/file.zip -s "Mail backup" -- alias@domain.com
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.