- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to send a file as an email attachment using the Linux command line?
In order to send a file as an attachment to an email using Linux, we either need to make use of a command line email client or the standard linux mail command.
There are multiple command line email clients available to achieve the attachment task, but the most common and widely used is mutt.
Mutt is a command line based email client that allows us to send and read emails from command line in Linux based systems. It also supports important protocols like IMAP and POP which broadens the use-cases and application of mutt.
Some of the key features that Mutt has are −
Easy to configure and install
Allows us to send attachments with emails
Allows message threading
Supports multiple languages.
In order to make use of mutt, we first need to install it on our local systems.
Consider the commands shown below for different versions that will help in installing mutt on the local machine.
For Linux Based Systems −
apt-get install mutt
For Centos/Fedora Systems −
yum install mutt
For Mac OS −
brew install mutt
Now once the mutt is installed we just need to write the following command to the terminal, and our mail along with the attachment will be sent to the email id.
echo "Message Body" | mutt -a "/file_to_attach" -s "subject of the message" -- firstname.lastname@example.org
Let’s break down the above command to understand it better, the mutt keyword is used to specify that we are making use of mutt email based client, followed by the -a flag which is used to denote that we are attaching some file along with the email which is followed by the path to that file, then we have a -s flag that is used to tell mutt that we are providing a subject for the email and lastly we have the email id to which we want to send the email.
One alternate way is to make use of the mail command utility that Linux provides us with.
Just write the following command to the terminal, and you will get the same result as the mutt command.
mail -s "Backup" -a mysqldbbackup.sql email@example.com < mail-message.txt
We can either make use of the mail command utility or the mutt email client, both will work fine. It just so happens that the mutt email client offers more features and services.
- How to send an email with a file attachment in Android?
- How to send an email with a file attachment in Android using Kotlin?
- How to send an attachment in email using Swift?
- How to send an attachment in email using Swift(ios)?
- How to send a email with attachment using a JSP page?
- Sending an Attachment with email using Perl
- How to send email using PowerShell?
- How to read a file from command line using Python?
- How do we send an email using HTML forms?
- Send email using Java Program
- How to write into a file from command line using Python?
- How to send HTML email using Android App?
- How to get only the file name using find command on Linux?
- How to encrypt and decrypt a file using gpg command on linux
- How to send a report through email using Selenium Webdriver?