linux系统SendMail详细配置

来源:互联网 发布:adobe dw是什么软件 编辑:程序博客网 时间:2024/04/28 05:57

1、 安装相关服务
DNS
Mailserver(sendmail、imap)
2、 启动相关服务
Service named restart
Service sendmail restart
Service xinetd restart
Chkconfig ipop3 on
3、 配置DNS,添加MX纪录
配置DNS略
正/反向区间文件添加MX纪录
IN MX 10(优先级) mail.anniey.com
Mail IN A 192.168.1.100
4、 主配置文件
/etc/mail/sendmail.cf
搜索/smtp
Port=smtp,Addr=192.168.1.100
5、 接受域配置文件
Vi /etc/mail/local-host-names
添加
Anniey.com
192.168.1.100
6、中继转发配置文件
/etc/mail/access.db(不可访问)
Vi /etc/mail/access
添加
Anniey.com
192.168.1
退出
Makemap hash access.db < access
6、 添加用户
Useradd user01
Passwd user01

Useradd user02
Passwd user02
7、 重启服务
Service sendmail restart
Service xinetd restart

补:邮件用户别名,邮件域别名
A)用户别名
1、Vi /etc/aliases
别名 用户名
A01 user01
A02 user02
退出
2、Newaliases

B)邮件域别名
1、配置相关DNS略
2、添加域别名
Vi /etc/mail/sendmail.cw
Anniey.com
Johnny.com
退出
3、接受域配置文件
Vi /etc/mail/local-host-names
Anniey.com
Johnny.com
192.168.1.100
4、重启服务
Service named restart
Service sendmail restart
Service xinetd restart

补:启用smtp认证
1、 安装相关模块
Rpm –qa | grep sasl
Linux盘中:RedHat—〉RPMS—>sasl*
2、 修改 /etc/mail/sendmail.mc(sendmail.cf的源代码)
Vi /etc/mail/sendmail.mc
查询:43 TRUST_AUTH*
:44
:85 DAEMON_OPTION*
:92 DAEMON*
注:去掉dnl(注释)
3、 生成sendmail.cf
M4 sendmail.mc >sendmail.cf
4、删除部分中继,以免开后门
5、客户机
我的服务器要求身份验证

经过以上步骤后,应该就可以用Outlook Express正常发送邮件了,但这时还不能用Outlook Express从服务器端收取邮件的,因为sendmail默认状态并不具备POP3功能,我们还得自己安装并启用它。
1、安装pop3服务
  rpm -qa imap
  imap-2001a-18
  rpm -ivh imap-2001a-18.i386.rpm
  2.启用POP3服务。
  POP3服务:请先修改/etc/xinetd.d/ipop3文件,将其中的disable=yes改为disable=no后保存;然后重新启动xinetd程序来读取这个修改过的配置文件,使之生效。
  /etc/rc.d/init.d/xinetd restart







* 利用telnet 命令发送邮件 :
用telnet SMTP发送邮件(伪装163发给Gmail)
xuanfei@xuanfei-desktop:~$  telnet 127.0.0.1 25
Trying 127.0.0.1...
Connected to localhost (127.0.0.1).
Escape character is '^]'.
220 localhost.localdomain ESMTP Sendmail 8.13.8/8.13.8; Fri, 10 Aug 2007 19:27:20 +0800
helo root
250 localhost.localdomain Hello localhost [127.0.0.1] (may be forged), pleased to meet you
mail from: [email=xuanfei2046@163.com][color=#0000ff]xuanfei2046@163.com[/color][/email]   
250 2.1.0 [email=xuanfei2046@163.com][color=#0000ff]xuanfei2046@163.com[/color][/email]... Sender ok
rcpt [url=http://to:shutup:uanfei2046@gmail.com/]to:shutup:uanfei2046@gmail.com[/url]
250 2.1.5 [email=xuanfei2046@gmail.com][color=#0000ff]xuanfei2046@gmail.com[/color][/email]... Recipient ok
data.
500 5.5.1 Command unrecognized: "data."
data
354 Enter mail, end with "." on a line by itself
who are you:(
.
250 2.0.0 l7ABRKF5006423 Message accepted for delivery
quit
221 2.0.0 localhost.localdomain closing connection
Connection closed by foreign host.
xuanfei@xuanfei-desktop:~$

如果服务器smtp需要验证,helo完要输入
AUTH LOGIN
会一次提示你
334 VXNlcm5hbWU6

334 UGFzc3dvcmQ6
后边的内容是提示输入用户名和口令,信息是经过base64编码的
输入的用户名和口令也要经过编码,这里是一个编码、解码的工具
smtp认证通过后会显示
235 2.0.0 Authentication successful

在用data命令之后可以直接书写正文,但也按照下面的“mime-version:”、“from:”、“to:”、“cc:”、“subject:”、“content-type:” 等固定的格式分别进行书写。会让E-mail的显示及邮件头比较完整,如下:
mime-version: 1.0
from: xuanfei2046<[email=xuanfei2046@gmail.com][color=#0000ff]xuanfei2046@gmail.com[/color][/email]>
to: xuanfei<[email=xuanfei2046@163.com][color=#0000ff]xuanfei2046@163.com[/color][/email]>
cc: xuanfei2046 <[email=test@mama.com][color=#0000ff]test@mama.com[/color][/email]>
subject: helo
Content-Type: text/plain;charset="GB2312"