Chinaunix首页 | 论坛 | 博客
  • 博客访问: 547546
  • 博文数量: 201
  • 博客积分: 7734
  • 博客等级: 少将
  • 技术积分: 1994
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-09 19:18
文章分类

全部博文(201)

文章存档

2011年(28)

2010年(173)

分类: LINUX

2010-06-13 18:10:05

一、mail的相关知识与操作

1.查询域的mx记录
#dig -t mx example.com

2.mail相关协议的及对应端口
SMTP 25
POP3 110
POP3s 995
IMAP 143
IMAPs 993

SMTP

LMTP:本地发信
#mail -s "test" user1  本地发信

3.mail的发信过程(以postfix使用telnet为例)。

<1>. 发信端与收信端两部主机间会先经过一次握手 (ehlo) 的阶段,此时发信端被记录发信来源(并不是
 mail from)。 通过握手后就可以进行信件标头 (header) 的传送;

<2>. 此时收信端主机会分析标头的信息,若信件rcpt to: 主机名称为收信端主机,且该名称符合
mydestination 的设定,则该信件会开始收入贮存队列,并进一步送到 mailbox 当中; 若不符合
mydestination 的设定,
则终止连接且不会进行信件内容 (body) 的传送;

<3>. 若 rcpt to: 主机名称非为收信端(MTA)本身,则开始进行中继(relay) 的分析。

<4>. 中继过程首先分析该信件的来源是否符合信任的用户端 (这个用户端为步骤 1 所记录的发信主机) ,
亦即来源是否符合 mynetworks 的设定值, 若符合则开始收下信件贮,并等待 MDA 将信件再转递出去,
若不符 mynetworks 则继续下一步;

<5>. 分析信件来源或目标是否符合 relay_domains 的设定,若符合则信件将被收下至贮存队列,
并等待 MDA 将信件再转递出去;

<6>. 若这封信的标头信息都不符合上述的规范,则终止连接,并不会接受信件的内容资料。


* 请确定 /etc/aliases 这个档案的权限,仅能由系统信任的帐号来修改,通常其权限为 644 ;
* 请确定 Mail server 读取的资料库 (多半在 /etc/mail/ 或 /etc/postfix/ 底下的 *.db 档案),
例如 mailertable, access, virtusertable 等等,仅能由系统信任的使用者读取,其他一概不能读取,
通常权限为 640 ;
* 系统的伫列目录 (/var/spool/mqueue 或 /var/spool/postfix) 仅允许系统读取,通常权限为 700 ;
* 请确定 ~/.forward 这个档案的权限也不能设定成为任何人均可查阅的权限,否则您的 e-mail 资料
可能会被窃取~
* 总之,一般用户能够不用 ~/.forward 与 aliases 的功能,就不要使用!

二、sendmail
安装

sendmail-8.13.8-2.el5  缺省已安装  
sendmail-cf-8.13.8-2.el5 
sendmail-doc-8.13.8-2.el5
sendmail-devel-8.13.8-2.el5


yum -y install sendmail*

vim /etc/mail/sendmail.mc

m4 宏语言中

dnl +空格为注释

1.将只侦听到127.0.0.1的一行注释,或改成0.0.0.0

dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl

m4 sendmail.mc > sendmail.cf RHEL5后此行可略
service sendmail restart  修改即可生效。

2.Add to /etc/mail/local-host-names

#vim /etc/mail/local-host-names  本MTA服务器在DNS内有多少别名就写多少。
--------------------------------------
# local-host-names - include all aliases for your machine here.

>>
station25.baidu.com
baidu.com

**************************

发送测试。

--------------------------------------
[root@client24 ~]# telnet 25
Trying 192.168.88.24...
Connected to (192.168.88.24).
Escape character is '^]'.
220 client24.google.com ESMTP Sendmail 8.13.8/8.13.8; Thu, 24 Sep 2009 03:21:10 +0800
mail from: ceo@google.com 发件地址
250 2.1.0 ceo@google.com... Sender ok
rcpt to : user1@baidu.com            收件地址
250 2.1.5 user1@baidu.com... Recipient ok
data
354 Enter mail, end with "." on a line by itself
Hi,baidu.com is good!              邮件正文
.                        以.结束正文
250 2.0.0 n8NJLAhU009805 Message accepted for delivery
quit                       退出
221 2.0.0 client24.google.com closing connection
Connection closed by foreign host.

**************************

3.安装pop3

yum -y install dovecot

service dovecot restart

此时将可使用thunderbird、mutt收发邮件了。


1.进来邮件的全局配置
2.出去邮件的全局配置
3.邮件进的别名
   a.本地别名
b.虚拟别名


4.伪装发信人的真实域。

 Step1:
#vim /etc/mail/sendmail.mc
 将以下行注释取消。
FEATURE(masquerade_envelope)dnl
Step2:
将以下行注释取消。
dnl MASQUERADE_AS(`mydomain.com')dnl
并修改为
  MASQUERADE_AS(`baidu.com')dnl
  接着在其下面手动加上一行
  FEATURE(masquerade_entire_domain)dnl
  重启服务。

 测试,收信人处只xxx@baidu.com域名。

5.邮件进来时的别名。



 a.本地别名(本地帐户)
  #vim /etc/aliases
在末尾添加以下内容
 user2: user1,user2
 user3: user1,user3
 user4: user1,user4
  即当给user2、user3、user4发邮件时,都会给user1抄送一份!
 重启服务。
  或者
 all : user1,user2,user3,user4 
  all在本地中不存在。这样发信人只要将地址写为all@baidu.com就可以同时给user1,user2,user3,user4
发信。即群发。
 it : it1,it2,it3
hr : hr1,hr2,hr3
cw : cw1,cw2,cw3
all : it,hr,cw
部分群发,且支持嵌套。

 b.虚拟别名


Virtual aliases: /etc/mail/virtusertable

admin@123.com shopper 当发送给123.com域内的admin时,自动转发给同域内的shopper
admin@xyz.org jdj 当发送给xyz.org域内的admin时,自动转发给同域内的jdj
pageme@he.net lmiwtc@pg.com 当发送给pageme@he.netn时,却转发到另一个域的lmiwtc@pg.com
@cba.com cba@aol.com  转发整个域的时候,切记防止死循环。
@dom1.org %1@dom2.org  多用于域名更换。

6.中继(远程MUA通过MTA发件)

Add restrictions in /etc/mail/access


From:90trialspammer@aol.com REJECT      来自于另一个MTA的邮件是否接收 (来自MTA)
To:nobody@ ERROR:550 bad name通过服务器发向另一个MTA (发向MTA)
Connect:spamRus.net REJECT MUA等Client通过MTA发出邮件    (来自MUA)
Connect:204.168.23 REJECT
Connect:10.3 OK
From:virtualdomain1.com RELAY
To:user@dom9.com ERROR:550 mail discarded
Connect:192.168.0 代表一个网段 RELAY
from ,to 没有明确拒绝  则允许
connect  没有明确允许  则拒绝
ERROR:MUA 指定错误信息。
RELAY:中继
REJECT:拒绝,错误信息
DISCARD:拒绝,无信息
OK:无条件放行


mail -v user   sendmail测试


#

mailq and mailq -Ac 队列消息。查看列表中未发出去的邮件。
view messages queued for future delivery
/var/spool/mqueue 队列存放位。
||||||
/var/spool/clientmqueue

sendmail -q 强制发送队列中的邮件。

7.Dovecot

   Post Office Protocol(POP3)邮件接收协议。
o

All data, including passwords, is passed in cleartext over TCP port 110
o

Use POP3s to provide SSL encryption of data over TCP port 995
                  即POP3S来保证数据的安全。

Internet Mail Access Protocol 
o  首先列出邮件头,从而选择接收顺序,先接收重要紧急的邮件。

All data, including passwords, is passed in cleartext over TCP port 143
o

Use IMAPs to provide SSL encryption of data over TCP port 993

Dovecot supports POP3, POP3s, IMAP, and IMAPs

      Dovecot同时支持以上四种协议。

Service Profile: Dovecot


*

Type: SystemV-managed service
*

Package: dovecot
*

Daemon: /usr/sbin/dovecot
*

Script: /etc/init.d/dovecot
*

Ports: 110 (pop), 995 (pop3s), 143 (imap), 993 (imaps)
*

Configuration: /etc/dovecot.conf
*

Related: procmail, fetchmail, openssl
:wq

8.加密
do
#cd /etc/pki/tls
#cd certs
#make dovecot.pem
#cp dovecot ../private
#vim /etc/dovecot.conf
>>>
ssl_cert_file = /etc/pki/tls/certs/dovecot.pem 公钥存放路径
ssl_key_file = /etc/pki/tls/private/dovecot.pem  私钥存放路径

#service dovecot restart

收取pops的邮件

mutt -f imap://user@server[:port]
mutt -f imaps://user@server[:port]


三、postfix
Service Profile: Postfix


Type: SystemV-managed service
*

Package: postfix
*

Daemons: /usr/libexec/postfix/master and others
*

Script: /etc/init.d/postfix
*

Port: 25 (smtp)
*

Configuration: /etc/postfix/main.cf and others
*

Related: procmail



1.安装


#yum -y install postfix
#yum -y install system-switch-mail
#system-switch-mail
>>选择postfix 即将sendmail切换到postfix
#service postfix start
#chkconfig sendmail off 取消sendmail服务的开机生效
#chkconfig postfix on 使postfix开机生效。
[root@local ~]# netstat -tulnp|grep 25
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 10325/master(即postfix服务)  


/etc/postfix/main.cf
o

postconf
o

Display defaults: postconf -d 默认设置,非当前配置
o

Display current non-default settings: postconf -n  非默认设置,当前配置
o

Modify main.cf: postconf -e key=value    修改设置
o

Show supported map types: postconf -m   支持类型(语法、软件)


2. 修改postfix配置使之侦听网络上的所有计算机。

----------------------------
[root@local ~]# postconf -n |grep interfaces
inet_interfaces = localhost
                        说明当前只侦听在本机
***********************************************************
[root@local ~]# postconf -e inet_interfaces=all
[root@local ~]# postconf -n |grep interfaces
inet_interfaces = all              修改成功
***********************************************************

3.与sendmail的 /etc/mail/local-host-names 同样,将MTA的主机名、域名及其所有别名写入Postfix配置

[root@local ~]# vim /etc/postfix/main.cf

>>>
myhostname = station36.example.com 定义主机名
mydomain = example.com 定义域名
mydestination = $myhostname, localhost.$mydomain, localhost ,$mydomain 主配置

<<<
使用telnet进行收发测试。

4.伪装


To masquerade as a domain

myorigin = $mydomain 设置全局伪装
masquerade_exceptions = root


进来的虚拟伪装
Support for a virtual alias domain looks like:
#
# /etc/postfix/main.cf:
# virtual_alias_maps = hash:/etc/postfix/virtual
#
# Note: some systems use dbm databases instead of hash.
# See the output from "postconf -m" for available data-
# base types.
#
# /etc/postfix/virtual:
# virtual-alias.domain anything (right-hand content does not matter)
# postmaster@virtual-alias.domain postmaster
# user1@virtual-alias.domain address1
# user2@virtual-alias.domain address2, address3

Rehash the file: postmap /etc/postfix/virtual

出来的伪装

# The following shows a generic mapping with an indexed
# file. When mail is sent to a remote host via SMTP, this
# replaces his@localdomain.local by his ISP mail address,
# replaces her@localdomain.local by her ISP mail address,
# and replaces other local addresses by his ISP account,
# with an address extension of +local (this example assumes
# that the ISP supports "+" style address extensions).
#
# /etc/postfix/main.cf:
# smtp_generic_maps = hash:/etc/postfix/generic
#
# /etc/postfix/generic:
# his@localdomain.local hisaccount@hisisp.example
# her@localdomain.local heraccount@herisp.example
# @localdomain.local hisaccount+local@hisisp.example

Rehash the file: postmap /etc/postfix/generic

5.中继


# The following example uses an indexed file, so that the
# order of table entries does not matter. The example per-
# mits access by the client at address 1.2.3.4 but rejects
# all other clients in 1.2.3.0/24. Instead of hash lookup
# tables, some systems use dbm. Use the command "postconf
# -m" to find out what lookup tables Postfix supports on
# your system.
#
# /etc/postfix/main.cf:
# smtpd_client_restrictions =
# check_client_access hash:/etc/postfix/access
#
# /etc/postfix/access:
# 1.2.3 REJECT
# 1.2.3.4 OK
#
Rehash the file: postmap /etc/postfix/access






6.Archive all messages: always_bcc = address 抄送所有的邮件到……



[root@local ~]# postconf -d |grep bcc
always_bcc = 所有的邮件抄送给=
recipient_bcc_maps = 接收的邮件抄送给=
sender_bcc_maps = 发出的邮件抄送给=
[root@local ~]# postconf -d |grep bcc |always
-bash: always: command not found
[root@local~]# postconf -d |grep bcc |grep always
always_bcc =
[root@local ~]# postconf -d |grep bcc |grep always >> /etc/postfix/main.cf
[root@local ~]# vim /etc/postfix/main.cf

>>>>
always_bcc = boss@example.com
<<<<
测试。

7.

View deferred messages: postqueue -p 查看队列


Flush deferred messages: postqueue -f 强制发送


Follow log: tail -f /var/log/maillog 查看日志

四、MDA(Procmail,A Mail Delivery Agent)邮件传送代理

预处理:防垃圾、过滤、分发
阅读(898) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~