CentOS下配置SMTP
在服务器上配置一个SMTP邮件服务可能是在日常工作中经常会遇到的需要,比如在做一些简单测试的时候。
配置步骤无比简单,废话不说:
1,yum -y install mail
2,编辑/etc/mail.rc,配置一些smtp相关内容
3,没有了...
安装mail
详细输出过程,记录如下
[root@thatsit ~]# yum -y install mail 已加载插件:fastestmirror 设置安装进程 Loading mirror speeds from cached hostfile Could not get metalink https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=x86_64 error was 14: Peer cert cannot be verified or peer cert invalid * base: mirrors.yun-idc.com * epel: mirror.lzu.edu.cn * extras: mirrors.yun-idc.com * updates: mirrors.yun-idc.com base | 3.7 kB 00:00 extras | 3.4 kB 00:00 updates | 3.4 kB 00:00 解决依赖关系 --> 执行事务检查 ---> Package mailx.x86_64 0:12.4-8.el6_6 will be 安装 --> 完成依赖关系计算 依赖关系解决 =============================================================================================================================================================================================== 软件包 架构 版本 仓库 大小 =============================================================================================================================================================================================== 正在安装: mailx x86_64 12.4-8.el6_6 base 235 k 事务概要 =============================================================================================================================================================================================== Install 1 Package(s) 总下载量:235 k Installed size: 452 k 下载软件包: mailx-12.4-8.el6_6.x86_64.rpm | 235 kB 00:00 运行 rpm_check_debug 执行事务测试 事务测试成功 执行事务 正在安装 : mailx-12.4-8.el6_6.x86_64 1/1 warning: /etc/mail.rc created as /etc/mail.rc.rpmnew Verifying : mailx-12.4-8.el6_6.x86_64 1/1 已安装: mailx.x86_64 0:12.4-8.el6_6 完毕! [root@thatsit ~]#
配置SMTP
[root@shipeng01 ~]# vim /etc/mail.rc [root@thatsit ~]# cat /etc/mail.rc set from=my_test_mail_address@163.com set smtp=smtp.163.com set smtp-auth-user=my_test_mail_address set smtp-auth-password=passwd_of_my_test_mail_address123 set smtp-auth=login [root@thatsit ~]#
测试
[root@thatsit ~]# echo "hehe" | mailx -v -s "test" my_qq_number@qq.com Resolving host smtp.163.com . . . done. Connecting to 220.181.12.16 . . . connected. 220 163.com Anti-spam GT for Coremail System (163com[20141201]) >>> EHLO thatsit 250-mail 250-PIPELINING 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250-coremail 1Uxr2xKj7kG0xkI17xGrU7I0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2UrKfWhDUCa0xDrUUUUj 250-STARTTLS 250 8BITMIME >>> AUTH LOGIN 334 dXNlcm5hbWU6 >>> dGhhdHNtYWls 334 UGFzc3dvcmQ6 >>> IUAjdGhhdHNtYWlsMTIz 235 Authentication successful >>> MAIL FROM:<my_test_mail_address@163.com> 250 Mail OK >>> RCPT TO:<my_qq_number@qq.com> 250 Mail OK >>> DATA 354 End data with <CR><LF>.<CR><LF> >>> . 250 Mail OK queued as smtp12,EMCowADX78NadypYg6vqDA--.33888S2 1479178081 >>> QUIT 221 Bye [root@thatsit ~]#
mailx和mail的关系
这里大家可能也看到了,上面测试命令里用了mailx,跟有些文档里用的mail命令不一样,那么这两者之间的关系是什么呢?我们来看一下:
[root@thatsit ~]# which mail /bin/mail [root@thatsit ~]# ll /bin/mail lrwxrwxrwx 1 root root 22 11月 15 10:47 /bin/mail -> /etc/alternatives/mail [root@thatsit ~]# ll /etc/alternatives/mail lrwxrwxrwx 1 root root 10 11月 15 10:47 /etc/alternatives/mail -> /bin/mailx [root@thatsit ~]#
大家也看到了,其实mail就是mailx软链的软链。因此在使用上,这两个命令一样的:
[root@thatsit ~]# echo "hehe" | mail -v -s "test" my_qq_number@qq.com Resolving host smtp.163.com . . . done. Connecting to 220.181.12.11 . . . connected. 220 163.com Anti-spam GT for Coremail System (163com[20141201]) >>> EHLO thatsit 250-mail 250-PIPELINING 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250-coremail 1Uxr2xKj7kG0xkI17xGrU7I0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2UFbVUZKUCa0xDrUUUUj 250-STARTTLS 250 8BITMIME >>> AUTH LOGIN 334 dXNlcm5hbWU6 >>> dGhhdHNtYWls 334 UGFzc3dvcmQ6 >>> IUAjdGhhdHNtYWlsMTIz 235 Authentication successful >>> MAIL FROM:<my_test_mail_address@163.com> 250 Mail OK >>> RCPT TO:<my_qq_number@qq.com> 250 Mail OK >>> DATA 354 End data with <CR><LF>.<CR><LF> >>> . 250 Mail OK queued as smtp7,C8CowAD3FNqqeSpYj9soDQ--.40085S2 1479178674 >>> QUIT 221 Bye [root@thatsit ~]#
两封测试邮件的截图如下
DONE