一、安装sendmail、mailx
1.1 先检查是否安装了sendmail、mailx,查询命令:rpm -qa |egrep 'sendmail|mailx'

1.2 执行命令安装sendmail、mailx
项目 | 说明 | 安装命令 |
---|---|---|
sendmail | sendmail | yum install sendmail |
mailx | 发送邮件 | yum install mailx |


二、邮件设置,设置命令:vim /etc/mail.rc
2.1 在 /etc/mail.rc最后添加上以下信息(根据自己的情况修改)
# Set from address and smtp domain
set from=xxxxxxxx@xx.com smtp=smtp.xx.com
# Set Smtp authentication
set smtp-auth-user=xxxxxx@xx.com smtp-auth-password=xxxx smtp-auth=login

三、发送邮件及验证
3.1 使用下面简单的mail命令即可发送一封信给xxxxx@xxxxx.com
[root@localhost ~]# echo "Hello, this is a test mail" |mail -s "Linux发送邮件测试" xxxxx@xxxxx.com
注意:邮件内容缺失很容易会被判定为垃圾邮件,建议尽可能写全一点,比如使用如下示例方式验证
sendmail -t <<EOF
From:Mail test <xxxxx@xxxxx.com>
To:xxxxx@xxxxxx.com
Subject:Greetings from Mars
Hello, this is greetings from Mars.
EOF

3.2 接收验证


网友评论