CentOS Mail命令使用指南

邮件发送命令(sendmail)
简介 sendmail是一个功能强大的邮件发送工具,它可以用来发送邮件、转发邮件、读取邮件等,在CentOS系统中,sendmail是默认的邮件发送代理。
发送邮件的基本语法
sendmail -v -f 发件人邮箱 -t 收件人邮箱 -u 发件人用户名 -X smtp服务器地址 -xu 发件人邮箱用户名 -xp 发件人邮箱密码 -S smtp服务器地址 -oS smtp-auth=login -oS smtp-auth-user=发件人邮箱用户名 -oS smtp-auth-password=发件人邮箱密码 -oS smtp-auth=plain -t
发送带附件的邮件
sendmail -v -f 发件人邮箱 -t 收件人邮箱 -u 发件人用户名 -X smtp服务器地址 -xu 发件人邮箱用户名 -xp 发件人邮箱密码 -S smtp服务器地址 -oS smtp-auth=login -oS smtp-auth-user=发件人邮箱用户名 -oS smtp-auth-password=发件人邮箱密码 -oS smtp-auth=plain -t -A 附件文件路径
举例
sendmail -v -f test@example.com -t test2@example.com -u test -X smtp.example.com -xu test -xp testpassword -S smtp.example.com -oS smtp-auth=login -oS smtp-auth-user=test -oS smtp-auth-password=testpassword -oS smtp-auth=plain -t -A /path/to/attachment.txt
邮件接收命令(mail)
简介 mail是一个简单的邮件客户端,可以用来接收和发送邮件,在CentOS系统中,mail是默认的邮件客户端。
接收邮件的基本语法

mail -u 用户名
查看邮件列表
mail -u 用户名 -s
-
mail -u 用户名 -f 邮件编号
举例
mail -u test
邮件管理命令(mailx)
简介 mailx是一个功能更加强大的邮件客户端,它可以用来接收、发送、转发邮件等,在CentOS系统中,mailx是默认的邮件客户端。
发送邮件的基本语法
mailx -s "邮件主题" -f 发件人邮箱 -t 收件人邮箱 -u 发件人用户名 -X smtp服务器地址 -xu 发件人邮箱用户名 -xp 发件人邮箱密码 -S smtp服务器地址 -oS smtp-auth=login -oS smtp-auth-user=发件人邮箱用户名 -oS smtp-auth-password=发件人邮箱密码 -oS smtp-auth=plain -A 附件文件路径
发送带附件的邮件
mailx -s "邮件主题" -f test@example.com -t test2@example.com -u test -X smtp.example.com -xu test -xp testpassword -S smtp.example.com -oS smtp-auth=login -oS smtp-auth-user=test -oS smtp-auth-password=testpassword -oS smtp-auth=plain -A /path/to/attachment.txt
举例
mailx -s "邮件主题" -f test@example.com -t test2@example.com -u test -X smtp.example.com -xu test -xp testpassword -S smtp.example.com -oS smtp-auth=login -oS smtp-auth-user=test -oS smtp-auth-password=testpassword -oS smtp-auth=plain -A /path/to/attachment.txt
邮件客户端配置

配置文件 在CentOS系统中,邮件客户端的配置文件通常位于
/etc/mail目录下。配置文件内容 配置文件通常包含以下内容:
- 发件人邮箱地址
- SMTP服务器地址
- 发件人邮箱用户名
- 发件人邮箱密码
- 举例
# 发件人邮箱地址 set from test@example.com
SMTP服务器地址
set smtp=smtp.example.com
发件人邮箱用户名
set username test
发件人邮箱密码
set password testpassword
五、FAQs
Q1:如何使用sendmail发送带附件的邮件?
A1:使用sendmail发送带附件的邮件,需要在命令中添加`-A`参数,并指定附件文件的路径。
Q2:如何配置mailx客户端?
A2:配置mailx客户端,需要编辑`/etc/mail`目录下的配置文件,设置发件人邮箱地址、SMTP服务器地址、发件人邮箱用户名和密码。 
