Files
thpeetz-notes/Quellen/IT/A Command Line Email Client to Send Mails from Ter.md
T

158 lines
7.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: A Command Line Email Client to Send Mails from Terminal
source: https://www.tecmint.com/send-mail-from-command-line-using-mutt-command/
---
[A Command Line Email Client to Send Mails from Terminal](https://www.tecmint.com/send-mail-from-command-line-using-mutt-command/)
As a System admin, sometimes we need to send mails to users or someone else from the server and for that we used to go with a web based interface to send email, is it really that handy ? Absolutely No.
![<img width="96" height="96" src="../../_resources/1x1.trans.gif"/>](https://www.tecmint.com/wp-content/uploads/2013/10/Mutt-Command.png)
Mutt Command Line Email Client
Here in this tutorial, well be using the **mutt** (a terminal email client) command to send email from command line interlace.
##### What is Mutt?
**Mutt** is a command line based **Email** client. Its a very useful and powerful tool to send and read mails from command line in **Unix** based systems. Mutt also supports **POP** and **IMAP** protocols for receiving mails. It opens with a coloured interface to send Email which makes it user friendly to send emails from command line.
##### Mutt Features
Some other important features of **Mutt** is as follows:
1. Its very Easy to install and configure.
2. Allows us to send emails with **attachments** from the command line.
3. It also has the features to add **BCC** (**Blind carbon copy**) and **CC** (**Carbon copy**) while sending mails.
4. It allows message **threading**.
5. It provides us the facility of mailing **lists**.
6. It also support so many mailbox formats like **maildir**, **mbox**, **MH** and **MMDF**.
7. Supports at least **20** languages.
8. It also support **DSN** (**Delivery Status Notification**).
### How to Install Mutt in Linux
We can install **Mutt Client** in our Linux box very easily with any package installers as shown.
\# apt-get install mutt (For Debian / Ubuntu based system)
\# yum install mutt (For RHEL / CentOS / Fedora based system)
##### Configuration files
Configuration files of **Mutt Email** client.
1. **Main Configuration file**: To make changes globally for all users For mutt, you can make changes in its mail configuration file “**/etc/Muttrc**“.
2. **User Configuration file of Mutt** : If you want to set some specific configuration for a particular user for Mutt, you can configure those settings in **~/.muttrc** or **~/.mutt/muttrc** files.
##### Basic Syntax of mutt command
mutt options recipient
##### Read Emails with Mutt
To read emails of the user with you are currently logged in, you just need to run “**mutt**” on the terminal, it will load the current users mailbox.
\[root@tecmint ~\]# mutt
![<img width="96" height="96" src="../../_resources/1x1.trans.gif"/>](https://www.tecmint.com/wp-content/uploads/2013/10/Mutt-1.png)
Read Mail from Terminal
To read the emails of a specific user, you need to specify which mail file to read. For example, You (as **root**) wants to read mails of user “**John**“, you need to specify his mail file with “**-f”** option with mutt command.
\[root@tecmint ~\]# mutt -f /var/spool/mail/john
You may also use “**-R**” option to open a mailbox in **read-only** mode.
##### Send an email with mutt command
In this example, following command will send a test **Email** to **john@tecmint.com**. The “**-s**” option is used to specify **Subject** of the mail.
\[root@tecmint ~\]# mutt -s "Test Email" john@tecmint.com
When you enter the above command in the terminal, it opens up with an interface and confirms the recipient address and subject of the mail and opens up the interface, here you can make changes to recipient mail address.
1. Change recipient email address pressing **t**.
2. Change Cc address with **c**.
3. Attach files as attachments with **a**.
4. Quit from the interface with **q**.
5. Send that email by pressing **y.**
**Note**: When you press “**y**” it shows the status below that mutt is sending mail.
![<img width="96" height="96" src="../../_resources/1x1.trans.gif"/>](https://www.tecmint.com/wp-content/uploads/2013/10/Mutt-2.png)
Send Mail from Terminal
##### Add Carbon copy(Cc) and Blind Carbon copy(Bcc)
We can add **Cc** and **Bcc** with mutt command to our email with “**-c**” and “**-b**” option.
\[root@tecmint ~\]# mutt -s "Subject of mail" -c &lt;email add for CC&gt; -b &lt;email-add for BCC&gt; mail address of recipient
\[root@tecmint ~\]# mutt -s “Test Email” -c tecmint.com@gmail.com -b root@server1.tecmint.com john@server1.tecmint.com
Here in this example, **root** is sending email to **john@server1.tecmint.com** and putting **tecmint.com@gmail.com** as **Cc** address and **root@server1.tecmint.com** as **Bcc**.
![<img width="96" height="96" src="../../_resources/1x1.trans.gif"/>](https://www.tecmint.com/wp-content/uploads/2013/10/Mutt-3.png)
Send Mail as CC or BCC in Terminal
##### Send Emails with Attachments
We can send email from command line with **attachments** by using “**-a**” option with mutt command.
\[root@tecmint ~\]# mutt -s "Subject of Mail" -a &lt;path of attachment file&gt; -c &lt;email address of CC&gt; mail address of recipient
\[root@tecmint ~\]# mutt -s "Site Backup" -a /backups/backup.tar -c tarunika@centos58server.example.com root@centos58server.example.com
![Send Email Attachment from Command LIne](https://www.tecmint.com/wp-content/uploads/2013/10/Mutt-4.png)
Send Email Attachment from Terminal
Here in above snapshot, you can see that it shows attachment attached with the mail.
##### Use of muttrc file
If we want to change the senders name and email, then we need to Create a file in that particular users home directory.
\[root@tecmint ~\]# cat .muttrc
Add the following lines to it. Save and close it.
set from = "user@domain.com"
set realname = "Realname of the user"
##### Getting Help
To print the help menu of “**mutt**”, we need to specify “**-h**” option with it.
\[root@tecmint ~\]# mutt -h
Mutt 1.4.2.2i (2006-07-14)
usage: mutt \[ -nRyzZ \] \[ -e &lt;cmd&gt; \] \[ -F &lt;file&gt; \] \[ -m &lt;type&gt; \] \[ -f &lt;file&gt; \]
mutt \[ -nx \] \[ -e &lt;cmd&gt; \] \[ -a &lt;file&gt; \] \[ -F &lt;file&gt; \] \[ -H &lt;file&gt; \]
mutt \[ -i &lt;file&gt; \] \[ -s &lt;subj&gt; \] \[ -b &lt;addr&gt; \] \[ -c &lt;addr&gt; \] &lt;addr&gt; \[ ... \]
mutt \[ -n \] \[ -e &lt;cmd&gt; \] \[ -F &lt;file&gt; \] -p -v\[v\]
options:
-a &lt;file&gt; attach a file to the message
-b &lt;address&gt; specify a blind carbon-copy (BCC) address
-c &lt;address&gt; specify a carbon-copy (CC) address
-e &lt;command&gt; specify a command to be executed after initialization
-f &lt;file&gt; specify which mailbox to read
-F &lt;file&gt; specify an alternate muttrc file
-H &lt;file&gt; specify a draft file to read header from
-i &lt;file&gt; specify a file which Mutt should include in the reply
-m &lt;type&gt; specify a default mailbox type
-n causes Mutt not to read the system Muttrc
-p recall a postponed message
-R mailbox in read-only mode
-s &lt;subj&gt; 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
This is it with **mutt command** for now, read **man pages** of mutt for more information on mutt command.