使用mailx邮件客户端发信、收信
2015-12-22 TsengYia@126.com http://tsengyia.blog.chinaunix.net
#################################################################
系统环境:
RHEL 6.5 [2.6.32-431.el6.x86_64]
软件环境:
postfix-2.6.6-2.2.el6_1.x86_64 (SMTP服务 )
dovecot-2.0.9-7.el6.x86_64 (IMAP、POP3服务)
cyrus-sasl-2.1.23-13.el6_3.1.x86_64 (SMTP认证组件)
mailx-12.4-7.el6.x86_64(客户端程序)
#################################################################
一、邮件服务端简单配置
1. 安装软件包、添加邮箱用户
[root@svr5 ~]# yum -y install postfix dovecot cyrus-sasl
[root@svr5 ~]# useradd mike
[root@svr5 ~]# echo 1234567 | passwd --stdin mike
[root@svr5 ~]# useradd hunter
[root@svr5 ~]# echo 1234567 | passwd --stdin hunter
2. 启动saslauthd服务
若不做SMTP认证的话,可以跳过此步
[root@svr5 ~]# service saslauthd restart
[root@svr5 ~]# testsaslauthd -u mike -p 1234567 -s smtp
0: OK "Success."
3. 配置启动postfix服务
[root@svr5 ~]# cp /etc/postfix/main.cf{,.bak}
[root@svr5 ~]# postconf -n > tmp.txt //提取邮箱配置
[root@svr5 ~]# mv tmp.txt /etc/postfix/main.cf
[root@svr5 ~]# vim /etc/postfix/main.cf
.. ..
mydomain = example.com //主邮件域
myhostname = mail.example.com
myorigin = $mydomain //发件域
mydestination = $mydomain, $myhostname, localhost.$mydomain, localhost //本地投递域
home_mailbox = Maildir/ //邮箱名称(末尾带/表示maildir类型,而不是mbox)
.. ..
mynetworks = 127.0.0.1 //定义信任网络
smtpd_sasl_auth_enable = yes //启用SMTP认证
smtpd_sasl_security_options = noanonymous
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_unauth_destination
[root@svr5 ~]# service dovecot restart
4. 配置启动dovecot服务
[root@svr5 ~]# vim /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no //允许明文认证
[root@svr5 ~]# vim /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir //指定邮箱类型和路径
5. 本地发信、收信测试
—— 用户mike给hunter发一封邮件
[root@svr5 ~]# echo AAAA | mail -s "AAAA" -r mike@example.com hunter@example.com
—— 收取用户hunter的邮件
[root@svr5 ~]# mail -f ~hunter/Maildir
Heirloom Mail version 12.4 7/29/08. Type ? for help.
"/home/hunter/Maildir": 1 messages 1 new
>N 1 mike@example.com Tue Dec 15 21:47 17/497 "A"
& t 1 //查看邮件内容
.. ..
& quit //退出mail终端
"/home/hunter/Maildir" complete
[root@svr5 ~]#
二、客户端mailx配置
1. 设置/etc/mail.rc文件 或 ~/.mailrc
[root@pc205 ~]# vim ~/.mailrc
set smtp=smtp://mail.example.com
set from=mike@example.com
set smtp-auth-user="mike@example.com"
set smtp-auth-password="1234567"
set folder=imap://mike@mail.example.com
set password-mike@mail.example.com="1234567"
2. 测试发信
[root@pc205 ~]# echo "Content Test" | mail -s "Test Mail 1." mike@example.com
或者
[root@pc205 ~]# mail -s "Test Mail 1." mike@example.com < mail.txt
3. 测试收信
[root@pc205 ~]# mail
Heirloom Mail version 12.4 7/29/08. Type ? for help.
"imap://mike@mail.example.com/INBOX": 1 message
> 1 To mike@example.com Tue Dec 15 21:21 /590 "N"
& t 1 //查看第1封邮件
.. ..
& quit
Held 1 message in imap://mike@mail.example.com/INBOX
#################################################################
阅读(2520) | 评论(0) | 转发(0) |