In this article, We are going to perform How to Install and Configure mutt on Ubuntu/CentOS 7.
Table of Contents
Introduction
Mutt is open source text based mail client which is used to transfer emails among hosts using Simple Mail Transfer Protocol (SMTP). It is widely used to send email using command line.
Prerequisite
- Ubuntu 18.04/16.04 LTS with Minimal Installation
- SSH Access with sudo privileges
- Open Firewall Port: 465/587,995
Update the System packages
$ sudo apt-get update
Install and Configure mutt on Ubuntu 18.04/16.04/CentOS 7
Ubuntu 18.04/16.04
Install mutt packages on Ubuntu using below command
$ sudo apt-get install mutt
CentOS 7
Install mutt packages on CentOS 7 using below command
$ sudo yum install mutt
Configuration of Mutt
First create the below directories.
$ mkdir -p ~/.mutt/cache/headers
$ mkdir ~/.mutt/cache/bodies
$ touch ~/.mutt/certificates
Creating mutt configuration File for GMail SMTP
Create the mutt configuration file
$ touch ~/.mutt/muttrc
Open the mutt configuration file using your favorite editor
$ sudo nano ~/.mutt/muttrc
Add below Email Configuration details, here we are using Gmail SMTP details
set realname = "FOSS TechNix Email Testing" set from = "<gmail username>@gmail.com" set use_from = yes set envelope_from = yes set smtp_url = "smtps://<gmail username>@[email protected]:465/" set smtp_pass = "<app password>" set imap_user = "<gmail username>@gmail.com" set imap_pass = "<app password>" set folder = "imaps://imap.gmail.com:993" set spoolfile = "+INBOX" set ssl_force_tls = yes # GMail to get mail bind index G imap-fetch-mail set editor = "nano" set charset = "utf-8" set record = ''
Creating mutt configuration File for Office365 SMTP
Create the mutt configuration file
$ touch ~/.mutt/muttrc
Open the mutt configuration file using your favorite editor
$ sudo nano ~/.mutt/muttrc
Add below Email Configuration details, here we are using office365 SMTP details
set realname = "<first and last name>" set from = ""<office365 username>@<domain-name>.com" set use_from = yes set envelope_from = yes set smtp_url = "smtp://<username>@<domain-name>[email protected]:587/" set smtp_pass = ""<Email password>"" set imap_user = "<office365 username>@<domain-name>.com " set imap_pass = "<Email password>" set folder = "imaps://outlook.office365.com:993" set spoolfile = "+INBOX" set ssl_force_tls = yes # To get mail bind index imap-fetch-mail set editor = "nano" set charset = "utf-8" set record = ''
Running Mutt
Once you have done adding Gmail smtp details in mutt configuration file, run the mutt command to downloading messages and sending emails.
$ mutt
Type m to start sending new messages, it will ask for recipient email, subject,body message,attach a file and press y to send email.
mutt command line options to send email
1. mutt command to Send mail with Subject and Body Message
$ mutt -s "Testing Email from mutt" [email protected] < /home/fosstechnix/test.txt
2. mutt command to send email with body message piped using the echo command
$ echo "Body Message" | mutt -s "Testing Email from mutt" [email protected]
3. mutt command to send email with attachment
$ echo "Body Message" | mutt -s "Testing Email from mutt" [email protected] -a /tmp/test.tar.gz
4. mutt command to send email with multiple attachments
$ echo "Body Message" | mutt -s "Testing Email from mutt" [email protected] -a test.tar.gz –a test2.tar.gz
5. mutt command to send email with multiple recipients
$ mutt -s “Testing Email from mutt” [email protected], [email protected], [email protected]
mutt command line help
Run below command to see more options and man pages of mutt.
$ mutt -h
Output:
Mutt 1.9.4 (2018-02-28) usage: mutt [<options>] [-z] [-f <file> | -yZ] mutt [<options>] [-Ex] [-Hi <file>] [-s <subj>] [-bc <addr>] [-a <file> [...] --] <addr> [...] mutt [<options>] [-x] [-s <subj>] [-bc <addr>] [-a <file> [...] --] <addr> [...] < message mutt [<options>] -p mutt [<options>] -A <alias> [...] mutt [<options>] -Q <query> [...] mutt [<options>] -D mutt -v[v] options: -A <alias> expand the given alias -a <file> [...] -- attach file(s) to the message the list of files must be terminated with the "--" sequence -b <address> specify a blind carbon-copy (BCC) address -c <address> specify a carbon-copy (CC) address -D print the value of all variables to stdout -d <level> log debugging output to ~/.muttdebug0 -E edit the draft (-H) or include (-i) file -e <command> specify a command to be executed after initialization -f <file> specify which mailbox to read -F <file> specify an alternate muttrc file -H <file> specify a draft file to read header and body from -i <file> specify a file which Mutt should include in the body -m <type> specify a default mailbox type -n causes Mutt not to read the system Muttrc -p recall a postponed message -Q <variable> query a configuration variable -R open mailbox in read-only mode -s <subj> specify a subject (must be in quotes if it has spaces) -v show version and compile-time definitions -x simulate the mailx send mode -y select a mailbox specified in your `mailboxes' list -z exit immediately if there are no messages in the mailbox -Z open the first folder with new message, exit immediately if none -h this help message
Finally, We have performed How to Install and Configure mutt on Ubuntu/CentOS.
Conclusion
In this article, We have have covered, install and configure mutt ,Created mutt Authentication File, mutt command line options to send email and mutt command help and man page.
How to Configure Sendmail to Relay Emails using Gmail SMTP on Ubuntu 18.04/16.04 LTS
How to Install and Configure OpenVPN on Ubuntu
Reference: