Mutt - 从终端发送邮件的命令行电子邮件客户端
作为系统管理员,有时我们需要从服务器向用户或其他人发送邮件,为此我们过去常常使用基于 Web 的界面来发送电子邮件,它真的那么方便吗?绝对没有。
在本教程中,我们将使用 mutt (终端电子邮件客户端)命令从命令行界面发送电子邮件。
穆特是什么?
Mutt 是一个基于命令行的电子邮件客户端。它是一个非常有用且强大的工具,可以在基于 Unix 的系统中从命令行发送和阅读邮件。 Mutt 还支持POP 和IMAP 协议来接收邮件。它以彩色界面打开来发送电子邮件,这使得用户可以友好地从命令行发送电子邮件。
杂种狗特征
Mutt 的其他一些重要特性如下:
- 它非常容易安装和配置。
- 允许我们从命令行发送带有附件的电子邮件。
- 它还具有在发送邮件时添加BCC(密件抄送)和CC(抄送)的功能。
- 它允许消息线程化。
- 它为我们提供了邮寄列表的功能。
- 它还支持多种邮箱格式,例如maildir、mbox、MH和MMDF。
- 支持至少20种语言。
- 它还支持DSN(递送状态通知)。
如何在 Linux 中安装 Mutt
我们可以使用所示的任何软件包安装程序非常轻松地在 Linux 机器中安装 Mutt Client。
apt-get install mutt (For Debian / Ubuntu based system)
yum install mutt (For RHEL / CentOS / Fedora based system)
配置文件
Mutt Email客户端的配置文件。
- 主配置文件:对所有用户进行全局更改 对于 mutt,您可以在其邮件配置文件“/etc/Muttrc”中进行更改。
- Mutt的用户配置文件:如果你想为Mutt的特定用户设置一些特定的配置,你可以在~/.muttrc或~中配置这些设置/.mutt/muttrc 文件。
mutt 命令的基本语法
mutt options recipient
与 Mutt 一起阅读电子邮件
要读取当前登录用户的电子邮件,您只需在终端上运行“mutt”,它就会加载当前用户的邮箱。
[root@tecmint ~]# mutt
要读取特定用户的电子邮件,您需要指定读取哪个邮件文件。例如,您(作为root)想要阅读用户“John”的邮件,您需要使用“-f”指定他的邮件文件 mutt 命令的选项。
[root@tecmint ~]# mutt -f /var/spool/mail/john
您还可以使用“-R”选项以只读模式打开邮箱。
使用 mutt 命令发送电子邮件
在此示例中,以下命令将发送测试电子邮件到[email 。 “-s”选项用于指定邮件的主题。
[root@tecmint ~]# mutt -s "Test Email" [email
当您在终端中输入上述命令时,会打开一个界面,确认邮件的收件人地址和主题,然后打开该界面,在这里您可以更改收件人邮件地址。
- 按 t 更改收件人电子邮件地址。
- 使用c更改抄送地址。
- 使用 a 将文件附加为附件。
- 使用q退出界面。
- 按y 发送该电子邮件。
注意:当您按“y”时,会显示下面的状态,表明 mutt 正在发送邮件。
添加抄送(Cc) 和密件抄送(Bcc)
我们可以使用 mutt 命令将抄送和密件抄送添加到我们的电子邮件中,并使用“-c”和“-b”选项。
[root@tecmint ~]# mutt -s "Subject of mail" -c <email add for CC> -b <email-add for BCC> mail address of recipient
[root@tecmint ~]# mutt -s “Test Email” -c [email -b [email [email
在此示例中,root 正在向 [email 发送电子邮件,并将 [email 设为抄送地址和[受保护的电子邮件]作为密件抄送。
发送带有附件的电子邮件
我们可以使用 mutt 命令的“-a”选项从命令行发送带有附件的电子邮件。
[root@tecmint ~]# mutt -s "Subject of Mail" -a <path of attachment file> -c <email address of CC> mail address of recipient
[root@tecmint ~]# mutt -s "Site Backup" -a /backups/backup.tar -c [email [email
在上面的快照中,您可以看到它显示了邮件附带的附件。
muttrc 文件的使用
如果我们想更改发件人姓名和电子邮件,那么我们需要在该特定用户的主目录中创建一个文件。
[root@tecmint ~]# cat .muttrc
将以下行添加到其中。保存并关闭它。
set from = "[email "
set realname = "Realname of the user"
寻求帮助
要打印“mutt”的帮助菜单,我们需要指定“-h”选项。
[root@tecmint ~]# mutt -h
Mutt 1.4.2.2i (2006-07-14)
usage: mutt [ -nRyzZ ] [ -e <cmd> ] [ -F <file> ] [ -m <type> ] [ -f <file> ]
mutt [ -nx ] [ -e <cmd> ] [ -a <file> ] [ -F <file> ] [ -H <file> ]
mutt [ -i <file> ] [ -s <subj> ] [ -b <addr> ] [ -c <addr> ] <addr> [ ... ]
mutt [ -n ] [ -e <cmd> ] [ -F <file> ] -p -v[v]
options:
-a <file> attach a file to the message
-b <address> specify a blind carbon-copy (BCC) address
-c <address> specify a carbon-copy (CC) address
-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 from
-i <file> specify a file which Mutt should include in the reply
-m <type> 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 <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
现在这就是 mutt 命令,请阅读 mutt 的手册页以获取有关 mutt 命令的更多信息。