Skip to content

Mutt — 一个通过终端发送邮件的Email客户端

mail3

作为一个系统管理员,有时我们需要发送邮件给客户或者服务器上的其他人,这时我们会使用基于web的邮件系统来发送邮件,这是不是最便捷的方法呢?绝对不是。
mail1

在这篇教程里,我们将使用mutt(一个终端email客户端)命令来从命令行发送邮件。

Mutt是什么?

Mutt是一个基于命令行的Email客户端。它是基于Unix的系统上发送和阅读邮件的十分强大而有用命令。Mutt也支持用POPIMAP协议接收邮件。它提供了一个彩色的界面使得从命令行发送邮件更加友好。

Mutt的特性

Mutt包含以下主要特性:

  • 易于安装和配置
  • 可以从命令行发送带附件的邮件
  • 支持在发送邮件时加入密送抄送
  • 支持消息会话
  • 可以显示邮件列表
  • 支持多种邮箱格式,例如maildirmboxMHMMDF
  • 支持至少20种语言
  • 支持DSN(Delivery Status Notification,投递状态通知)

如何在Linux上安装Mutt

我们可以在Linux上非常容易的使用任意包安装器安装Mutt客户端,像下面这样。

apt-get install mutt (For Debian / Ubuntu based system)
yum install mutt (For RHEL / CentOS / Fedora based system)

配置文件

Mutt Email客户端的配置文件:

  • Main Configuration file:改变是全局的,会影响所有用户的mutt,你可以通过它的邮件配置文件”/etc/Muttrc”进行更改。
  • User Configuration file of Mutt:如果你想为特定用户定制Mutt,你可以通过设置~/.muttrc或者~/.mutt/muttrc做到这一点。

基本的mutt命令语法

mutt options recipient

用Mutt阅读邮件

要阅读当前系统登录用户的邮件,你只需要在终端运行”mutt“, 它将会加载当前用户的邮箱。

mutt

mail2

要阅读指定用户的邮件,你需要告诉程序读取哪一个邮件文件。举个例子,你(root用户)想看用户”John”的邮件,你需要通过”-f”选项指定它的邮件文件。

mutt -f /var/spool/mail/john

你也可以用”-R”选项来打开只读模式。

通过mutt发送邮件

在这个例子里,下面的命令将会发送一封测试邮件john@tecmint.com。”-s”选项用于指定邮件的主题

mutt -s "Test Email" john@tecmint.com

当你在终端里键入了上面的命令并回车后,他会打开一个确认收件人地址和主题的界面,这这里你可以修改收件人地址。

  • t改变收件人地址
  • c改变抄送地址
  • a添加一个附件
  • q退出界面
  • y发送邮件

注意当你按了”y“界面下方将会显示发送状态。
mail3

添加抄送和密送

我们可以通过”-c”和”-b”选项添加抄送和密送。

 mutt -s "Subject of mail" -c  -b  mail address of recipient
mutt -s “Test Email” -c tecmint.com@gmail.com  -b root@server1.tecmint.com john@server1.tecmint.com

在这个例子里,用户root发送了一封邮件给john@server1.tecmint.com,抄送给了tecmint.com@gmail.com并且密送给了root@server1.tecmint.com
mail4

发送带附件的邮件

我们可以通过”-a”选项来添加一个附件。

mutt  -s "Subject of Mail" -a  -c   mail address of recipient
mutt -s "Site Backup" -a /backups/backup.tar  -c tarunika@centos58server.example.com root@centos58server.example.com

mail5

在上面的截图里,你可以看到邮件的附件列表。

使用muttrc文件

如果我们想改变发送人的名字和地址,我们需要在指定的用户home目录下创建一个文件。

cat .muttrc

加入下面的行,保存退出。

set from = "user@domain.com"
set realname = "Realname of the user"

获取帮助

你可以通过”-h“选项获取”mutt“的帮助菜单。

[root@tecmint ~]# mutt -h

Mutt 1.4.2.2i (2006-07-14)
usage: mutt [ -nRyzZ ] [ -e  ] [ -F  ] [ -m  ] [ -f  ]
       mutt [ -nx ] [ -e  ] [ -a  ] [ -F  ] [ -H  ] 
       mutt [ -i  ] [ -s  ] [ -b  ] [ -c  ]  [ ... ]
       mutt [ -n ] [ -e  ] [ -F  ] -p -v[v]
options:
  -a      attach a file to the message
  -b 
specify a blind carbon-copy (BCC) address -c
specify a carbon-copy (CC) address -e specify a command to be executed after initialization -f specify which mailbox to read -F specify an alternate muttrc file -H specify a draft file to read header from -i specify a file which Mutt should include in the reply -m 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 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

这就是mutt的命令了,阅读mutt的man page来获取更多mutt命令信息。

0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x