设为首页 收藏本站
查看: 1728|回复: 0

[经验分享] 搭建Sendmail邮件系统

[复制链接]

尚未签到

发表于 2015-11-25 15:06:06 | 显示全部楼层 |阅读模式
  搭建Sendmail邮件系统
  1                          ☆邮件系统
电子邮件系统的工作原理
  电子邮件系统的运作方式与其它的网络应用有着根本上的不同。在其它的绝大多数的网络应用中,网络协议直接负责将数据发送到目的
  地。而在电子邮件系统中,发送者并不等待发送工作完成,而是仅仅将要发送的内容发送出去。
  电子邮件的协议标准是TCP/IP协议族的一部分。它规定了电子邮件的格式和在邮局间交换电子邮件的协议。
  每个电子邮件都分为两部分:邮件头和邮件内容。TCP/IP对电子邮件的邮件头的格式作了确切的规定,而将邮件内容的格式让用户自定义。
  在邮件头中最重要的两个组成部分就是发送者和接收者的电子邮件地址。
  电子邮件地址的格式如下:
  用户名@电子邮局域名 例:abc@990.net
  电子邮件的传输协议(也就是在邮局间交换电子邮件的协议)主要有SMTP(简单邮件传输协议)、POP(电子邮局协议),以及现在新兴的IMAP(互联网邮件应用协议)。
  整个电子邮件应用系统由两大部分构成:
  1. 电子邮局系统;
  电子邮局行使着像传统邮局的功能,它在发送者和接收者之间起着一个桥梁作用。它是运行在电子邮局服务器上的一个服务器端程序。
  最常用的有Microsoft的IIS和sendmail等。
  2. 电子邮件发送、接收系统。
  电子邮件发送、接收系统则象遍及千家万户的邮箱,发送者和接收者通过它将邮件从电脑中发送和接收邮件。这个部分是一个运行在电
  脑中的客户端程序,最常用的有Microsoft的Outlook Express,Netscape,The Bat,Foxmail,方正飞扬等。
  有3种可提供的邮件服务
  MTA(Message Transfer Agent):消息传输代理(发送邮件服务器) sendmail, postfix, qmail
  MDA (Mail Delivery Agents):邮件传递代理(邮件处理器) procmail, maildrop
  MUA (Mail User Agent):邮件用户代理(邮件客户端上运行的程序) Mozilla, elm
  ☆邮件服务器
  邮件服务器是电子邮件系统的核心构件,它的主要功能是发送和接收邮件,同时向发件人报告邮件的传送情况。根据用途的不同,可以将
  邮件服务器分为发送邮件服务器(SMTP服务器)和接收邮件服务器(POP3服务器或IMAP4服务器)。
  sendmail和postfix。您可以选择任何一个MTA
  Sendmail并不处理最终的投递,当然也不会处理如何把邮件提交给最终用户这样的任务。一般来说,我们总是在Windows客户机器上处
  理各种电子邮件,因此需要一个服务程序负责将sendmail存储的邮件转交给Windows或其他任何客户机器。有两种基本的方法,一种是
  将邮件传送到客户的本地机器上处理,这是通过所谓的邮局协议实现的;另一种是允许用户远程操作其邮箱并且实现对邮件的浏览和管理,
  这是通过所谓的IMAP协议。
  2                          ☆SMTP协议
SMTP即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式。SMTP协议属于TCP/IP协议簇,它帮助每台计算机在发送或中转信件时找到下一个目的地。通过SMTP协议所指定的服务器,就可以把Email寄到收件人的服务器上了。SMTP服务器则是遵循SMTP协议的发送邮件服务器,用来发送或中转发出的电子邮件。
  3                          ☆POP3协议
POP3即邮局协议的第3个版本,它规定怎样将个人计算机连接到Internet的邮件服务器和下载电子邮件的协议。它是Internet电子邮件的第一个离线协议标准,POP3允许从服务器上把邮件存储到本地主机即自己的计算机上,同时删除保存在邮件服务器上的邮件。遵循POP3协议来接收电子邮件的服务器是POP3服务器。
  4                          ☆IMAP4协议
IMAP4即Internet信息访问协议的第4个版本,是用于从本地服务器上访问电子邮件的协议,它是一个客户/服务器模型协议,用户的电子邮件由服务器负责接收保存,用户可以通过浏览信件头来决定是否要下载此信。用户也可以在服务器上创建或更改文件夹或邮箱,删除信件或检索信件的特定部分。
  5                          ☆POP和IMAP差异
虽然POP和IMAP都是处理接收邮件的,但两者在机制上却有所不同。在用户访问电子邮件时,IMAP4需要持续访问服务器,POP3则是将信件保存在服务器上,当用户阅读信件时,所有内容都会被立即下载到用户的机器上。因此,可以把IMAP4看成是一个远程文件服务器,而把POP看成是一个存储转发服务器。就目前情况看,POP3的应用远比IMAP4广泛得多。
  6                          ☆mail
使用权限:所有使用者
  使用方式:mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] user1 [user 2 ...]
  说明:
  mail 不仅只是一个指令, mail 还是一个电子邮件程式,不过利用 mail 来读信的人应该很少吧!对于系统管理者来说 mail 就很有用,因为管理者可以用 mail 写成 script ,定期寄一些备忘录提醒系统的使用者。
  参数:
  i  忽略 tty 的中断讯号。 (interrupt)
  I  强迫设成互动模式。 (Interactive)
  v  列印出讯息,例如送信的地点、状态等等。 (verbose)
  n  不读入 mail.rc 设定档。
  s   邮件标题。
  c cc  邮件地址。
  b bcc  邮件地址。
  将信件送给一个或以上的电子邮件地址,由于没有加入其他的选项,使用者必须输入标题与信件的内容等。而 user2 没有主机位置,就会送给邮件伺服器的 user2 使用者。
  mail user1@email.address
  mail user1@email.address user2
  将 mail.txt 的内容寄给 user2 同时 cc 给 user1 。如果将这一行指令设成 crontab 就可以定时将备忘录寄给系统使用者。
  mail -s 标题 -c user1 user2 < mail.txt
  mail 查看/var/spool/mail/目录下自已邮箱内容(每个用户会有一个文件保存自己所有文件)。以q退出把看过的邮件保存在~/mbox文件中。
  mail test@panda.com 直接发邮件给人。
  mail -s 'title text' test@panda.com < mail.txt 把文档中内容邮寄出去。
  mail -f ~/mbox 查看home目录下邮箱内容。
  7                          ☆uuencode/uudecode
用mail发附件也是可行,要用到uuencode and uudecode命令进行编码。
  编码:uuencode [file] name
  uuencode hello >hello.uue
  default input is stdin;se
  default output is stdout.
  解码:uudecode [-o outfile] name
  uudecode hello.uue
  可以用-o选项输出另外一个文件名。
  # uuencode ~/.bashrc -o bashrc | mail -s 'test uuencode' test@panda.com
  8                          ☆system-switch-mail
切换sendmail和postfix
  9                          ☆sendmail
sendmail提供SMTP服务
  10              ☆sendmail安装
如果你在安装RHEL5的时候,选择了E-MAIL服务,sendmail就已经安装在LINUX系统中了,并且已经作了一些最基本的设置。
  sendmail-8.13.8-2.el5.i386.rpm       (第一张光盘,默认已装) sendmail软件包是sendmail服务器程序的安装包,是最重要的软件包.
  m4-1.4.5-3.el5.1.i386.rpm            (第一张光盘,默认已装)m4软件包中包括了配置sendmail服务器的必要工具.
  procmail-3.22-17.1.i386.rpm         (第一张光盘,默认已装)
  sendmail-cf-8.13.8-2.el5.i386.rpm     (第二张光盘,默认未装) sendmail-cf软件包中包括了重新配置sendmail服务器的必要配置文件.
  sendmail-doc-8.13.8-2.el5.i386.rpm   (第三张光盘,默认未装) sendmail-doc软件包中包括了sendmail服务器的说明文档.
  sendmail-devel-8.13.8-2.el5.i386.rpm  (第三张光盘,默认未装)  
  管理员需要手动安装以下两个包,才能配置sendmail服务器:#rpm -ivh sendmail-cf-8.13.8-2.el5.i386.rpm  sendmail-doc-8.13.8-2.el5.i386.rpm
  设置运行级别:#chkconfig --level 35 sendmail on
  11              ☆sendmail使用前配置
sendmail的DNS设置
  当sendmail程序得到一封待发送的邮件的时候,它需要根据目标地址确定将信件投递给那一个服务器,这是通过DNS服务实现的。例如,有一封邮件的目标地址是panda@panda.com,那么,sendmail首先确定这个地址是用户名(panda)+机器名(panda.com)的格式,然后,通过查询DNS来确定需要把信件投递给某个服务器。
  先用ifconfig查看服务器的ip,再把ip写入:
  #vi  /etc/resolv.conf
  ; generated by /sbin/dhclient-script
  search panda.com
  nameserver 192.168.152.128
  确认/etc/hosts,
  #vi /etc/hosts
  # Do not remove the following line, or various programs
  # that require network functionality will fail.
  127.0.0.1       panda.panda.com         panda   panda
  然后在/etc/named.conf中加入
  zone "panda.com" IN {
  type master;
  file "panda.com.zone";
  };
  最后生成/var/named/chroot/var/named/panda.com.zone
  $TTL    86400
  @ IN SOA panda.panda.com. root.panda.panda.com. (
  2006062700 ; Serial
  28800 ; Refresh
  14400 ; Retry
  3600000 ; Expire
  86400 ) ; Minimum
  IN     NS    panda
  IN     MX   10    panda
  panda  IN    A    192.168.152.128
  重启DNS.#service named restart
  DNS数据中,与电子邮件相关的是MX记录,这可以在查询DNS时设置查询类型为mx来得 到:
  [iyunv@panda ~]# nslookup
  > panda.panda.com
  Server:         192.168.152.128
  Address:        192.168.152.128#53
  Name:   panda.panda.com
  Address: 192.168.152.128
  > set q=mx
  > panda.com
  Server:         192.168.152.128
  Address:        192.168.152.128#53
  panda.com       mail exchanger = 10 panda.panda.com.
  在一般的情况下,mx交换器会自动把信件内容转交给目标主机,不过,也存在这样的情况 ,目标主机(比如panda.com)可能并不存在,或者不执行smtp服务,而是由其mx交换器来执行信件的管理,这时候,最终的信件将保存在mx机器上,直到用户来察看它。
  如果DNS查询无法找出对某个地址的MX记录(通常因为对方没有信件交换主机),那么sendmail将是试图直接与对方的主机(来自邮件地址)对话并且发送邮件。例如,test@china.com在DNS中没有对应的MX记录,因此sendmail在确定MX交换器失败后,将从DNS取得对方的IP地址并直接和对方对话试图发送邮件。
  sendmail发送邮件时,如果经过设定的时间后仍然未能将信件投递到目的主机,它将返回一个错误信息并且休息一段时间,然后重新试图投递,如果连续多次失败,sendmail最终将放弃投递并将错误信息投递给postmaster用户。在许多机器上,postmaster用户是root用户的一个别名(参考下面关于别名的内容),你应该将它设置为邮件的实际管理员的用户名。
  例如,你可能会用mail程序向某个地址这样发信:
  $mail someone@somedomain.com
  To:other@otherdomain.com
  Subject:test mail
  test
  someone@somedomain.com 必须准确到某台主机上
  那么,当sendmail发信的时候,它是向someone@somedomain.com发信而不是other@otherdomain.com。相应地,如果你想向两个人发信,例如你在outlook里面写上:"投递给user1@a.com,抄送user2@b.com",那么sendmail应该怎么做?直接同时向两个地址发信吗?否,它试图构造两个包装(称为信封),每个包装上只列出一个投递地址,各投递一次。虽然邮件正文的头部仍然包含两个地址,但是sendmail不会看它。
  配置文件
  /etc/sysconfig/sendmail
  DAEMON=yes
  QUEUE=1h
  每一个小时传递队列中的文件
  12              ☆sendmail防火墙
iptables -I INPUT -p tcp --dport 25 -j ACCEPT
  13              ☆sendmail启动
启动用:
  #service sendmail start ;#/etc/init.d/sendmail start;
  或 # sendmail  -bd  -q30m该命令以后台进程方式(-bd)运行,并使其每隔30分钟(-q30m)轮询一次未发送邮件队列,检查是否有新邮件。-q1h表示每隔一个小时发送一次邮件
  停止用:
  #service sendmail stop;#/etc/init.d/sendmail stop;#service sendmail restart ;
  14              ☆sendmail主要配置文件
  #ls  /etc/mail/
  access            helpfile           Makefile      submit.mc
  access.db         local-host-names   sendmail.cf    trusted-users
  domaintable      mailertable        sendmail.mc   virtusertable
  domaintable.db   mailertable.db      submit.cf     virtusertable.db
  #ls  /etc/aliases*
  /etc/aliases      /etc/aliases.db
  在/etc/mail目录中保存了sendmail服务器使用的所有配置文件,文件后缀是".cf"的是服务器配置文件,文件后缀是".db"的是服务器使用的数据库文件,下面是常用的文件说明:
  配置文件sendmail.cf和sendmail.mc
  sendmail服务器的主配置文件是sendmail.cf,该文件的格式是公认的难于理解,因此即使是有经验的管理员也会避免直接编辑此文件,sendmail开发人员为
  sendmail管理者提供了更加容易理解和配置的sendmail.mc文件。一般情况下,系统管理员对sendmail.mc文件的内容进行设置后,再使用m4命令由
  sendmail.mc文件的内容生成sendmail.cf文件。但由于sendmail.mc文件的配置依然有一定的难度,因此在第一次对sendmail.mc文件进行修改前,最好先将
  该文件进行备份,以便配置错误时能够恢复默认配置,操作流程如下:
  #cd /etc/mail                   (进入主配置文件目录)
  #cp sendmail.mc  sendmail.mc-  (备份配置文件sendmail.mc)
  #vi sendmail.mc                (编缉配置文件sendmail.mc)
  #m4 sendmail.mc > sendmail.cf   (利用m4命令重新生成主配置文件sendmail.cf)
  #service sendmail restart         (重启sendmail服务使配置生效)
  注意:sendmail服务器在运行时只读取sendmail.cf文件中的设置,因此每次对sendmail.mc文件进行修改后都需要使用m4命令生成新的sendmail.cf文件,  
  而且m4命令必须在/etc/mail/目录中执行。
  数据库配置文件和数据库文件
  在sendmail服务器中除了sendmail.cf主配置文件以外,还使用了许多数据库文件辅助进行sendmail服务器的配置。在/etc/mail目录中所有扩展名为".db" 的
  文件都是数据库文件,这些数据库文件的格式对于用户是不可读的。每个".db"数据库文件在同一目录下都对应有同名的无扩展名文件,例如对于access.db
  文件,对应有名为access的文本文件,access文件是用于系统管理员进行管理的,称为数据库配置文件。当管理员在数据库配置文件(文本文件)中进行了相
  应的设置后,需要使用makemap命令将数据库配置文件生成".db"的数据库文件,因为sendmail服务器只能够识别".db"的数据库文件中的配置内容。操  
  作流程如下:
  #cd /etc/mail        (进入数据库文件目录)
  #vi  access         (编辑数据库配置文件)
  #makemap  hash  access.db  <access   (用makemap命令重新生成数据库文件)
  #service sendmail restart    (重启sendmail服务让配置生效)
  ☆sendmail.mc
sendmail.mc文件中指令的意义:
  指令
意义

divert (-1)
删除结果文件中的垃圾

divert (0)
保存通常的配置文件

Dnl
注解

Include
包含一个文件

define arg1 arg2
定义宏arg1设置为arg2

undefine arg1
取消arg1的定义

OSTYPE ('Linux')
定义操作系统类型

FEATURE
功能选项,对应/usr/lib/sendmail-cf/feature里定义的文件名称

MAILER
定义所有必要的邮件投递代理程序

ASQUERADE_AS
用来处理多主机名称问题

  divert(-1)dnl
  dnl #
  dnl # This is the sendmail macro config file for m4. If you make changes to
  dnl # /etc/mail/sendmail.mc, you will need to regenerate the
  dnl # /etc/mail/sendmail.cf file by confirming that the sendmail-cf package is
  dnl # installed and then performing a
  dnl #     make -C /etc/mail
  include(`/usr/share/sendmail-cf/m4/cf.m4')dnl
  VERSIONID(`setup for linux')dnl
  OSTYPE(`linux')dnl    //设定使用的操作系统类别
  dnl # Do not advertize sendmail version.
  dnl define(`confSMTP_LOGIN_MSG', `$j Sendmail; $b')dnl
  dnl # default logging level is 9, you might want to set it higher to
  dnl # debug the configuration
  dnl define(`confLOG_LEVEL', `9')dnl
  dnl # Uncomment and edit the following line if your outgoing mail needs to
  dnl # be sent out through an external mail server:
  dnl define(`SMART_HOST', `smtp.your.provider')dnl
  define(`confDEF_USER_ID', ``8:12'')dnl
  dnl define(`confAUTO_REBUILD')dnl
  define(`confTO_CONNECT', `1m')dnl
  define(`confTRY_NULL_MX_LIST', `True')dnl
  define(`confDONT_PROBE_INTERFACES', `True')dnl
  define(`PROCMAIL_MAILER_PATH', `/usr/bin/procmail')dnl
  define(`ALIAS_FILE', `/etc/aliases')dnl
  define(`STATUS_FILE', `/var/log/mail/statistics')dnl
  define(`UUCP_MAILER_MAX', `2000000')dnl
  define(`confUSERDB_SPEC', `/etc/mail/userdb.db')dnl
  define(`confPRIVACY_FLAGS', `authwarnings,novrfy,noexpn,restrictqrun')dnl
  define(`confAUTH_OPTIONS', `A')dnl
  dnl # The following allows relaying if the user authenticates, and disallows
  dnl # plaintext authentication (PLAIN/LOGIN) on non-TLS links
  dnl define(`confAUTH_OPTIONS', `A p')dnl
  dnl # PLAIN is the preferred plaintext authentication method and used by
  dnl # Mozilla Mail and Evolution, though Outlook Express and other MUAs do
  dnl # use LOGIN. Other mechanisms should be used if the connection is not
  dnl # guaranteed secure.
  dnl # Please remember that saslauthd needs to be running for AUTH.
  ddnl TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
  dnl define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
  dnl # Rudimentary information on creating certificates for sendmail TLS:
  dnl #     cd /usr/share/ssl/certs; make sendmail.pem
  dnl # Complete usage:
  dnl #     make -C /usr/share/ssl/certs usage
  dnl define(`confCACERT_PATH', `/etc/pki/tls/certs')dnl
  dnl define(`confCACERT', `/etc/pki/tls/certs/ca-bundle.crt')dnl
  dnl define(`confSERVER_CERT', `/etc/pki/tls/certs/sendmail.pem')dnl
  dnl define(`confSERVER_KEY', `/etc/pki/tls/certs/sendmail.pem')dnl
  dnl # This allows sendmail to use a keyfile that is shared with OpenLDAP's
  dnl # slapd, which requires the file to be readble by group ldap
  dnl define(`confDONT_BLAME_SENDMAIL', `groupreadablekeyfile')dnl
  dnl define(`confTO_QUEUEWARN', `4h')dnl
  dnl define(`confTO_QUEUERETURN', `5d')dnl
  dnl define(`confQUEUE_LA', `12')dnl
  dnl define(`confREFUSE_LA', `18')dnl
  define(`confTO_IDENT', `0')dnl
  dnl FEATURE(delay_checks)dnl
  FEATURE(`no_default_msa', `dnl')dnl
  FEATURE(`smrsh', `/usr/sbin/smrsh')dnl
  FEATURE(`mailertable', `hash -o /etc/mail/mailertable.db')dnl
  FEATURE(`virtusertable', `hash -o /etc/mail/virtusertable.db')dnl
  FEATURE(redirect)dnl
  FEATURE(always_add_domain)dnl
  FEATURE(use_cw_file)dnl
  FEATURE(use_ct_file)dnl
  dnl # The following limits the number of processes sendmail can fork to accept
  dnl # incoming messages or process its message queues to 20.) sendmail refuses
  dnl # to accept connections once it has reached its quota of child processes.
  dnl define(`confMAX_DAEMON_CHILDREN', `20')dnl
  dnl # Limits the number of new connections per second. This caps the overhead
  dnl # incurred due to forking new sendmail processes. May be useful against
  dnl # DoS attacks or barrages of spam. (As mentioned below, a per-IP address
  dnl # limit would be useful but is not available as an option at this writing.)
  dnl define(`confCONNECTION_RATE_THROTTLE', `3')dnl
  dnl # The -t option will retry delivery if e.g. the user runs over his quota.
  FEATURE(local_procmail, `', `procmail -t -Y -a $h -d $u')dnl
  FEATURE(`access_db', `hash -T<TMPF> -o /etc/mail/access.db')dnl
  FEATURE(`blacklist_recipients')dnl    //允许使用黑名单查禁收件人。因此用户可以在access文件中设定黑名单。
  EXPOSED_USER(`root')dnl
  dnl # For using Cyrus-IMAPd as POP3/IMAP server through LMTP delivery uncomment
  dnl # the following 2 definitions and activate below in the MAILER section the
  dnl # cyrusv2 mailer.
  dnl define(`confLOCAL_MAILER', `cyrusv2')dnl
  dnl define(`CYRUSV2_MAILER_ARGS', `FILE /var/lib/imap/socket/lmtp')dnl
  dnl # The following causes sendmail to only listen on the IPv4 loopback address
  dnl # 127.0.0.1 and not on any other network devices. Remove the loopback
  dnl # address restriction to accept email from the internet or intranet.
  DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
  dnl # The following causes sendmail to additionally listen to port 587 for
  dnl # mail from MUAs that authenticate. Roaming users who can't reach their
  dnl # preferred sendmail daemon due to port 25 being blocked or redirected find
  dnl # this useful.
  dnl DAEMON_OPTIONS(`Port=submission, Name=MSA, M=Ea')dnl
  dnl # The following causes sendmail to additionally listen to port 465, but
  dnl # starting immediately in TLS mode upon connecting. Port 25 or 587 followed
  dnl # by STARTTLS is preferred, but roaming clients using Outlook Express can't
  dnl # do STARTTLS on ports other than 25. Mozilla Mail can ONLY use STARTTLS
  dnl # and doesn't support the deprecated smtps; Evolution <1.1.1 uses smtps
  dnl # when SSL is enabled-- STARTTLS support is available in version 1.1.1.
  dnl # For this to work your OpenSSL certificates must be configured.
  dnl #
  dnl DAEMON_OPTIONS(`Port=smtps, Name=TLSMTA, M=s')dnl
  dnl # The following causes sendmail to additionally listen on the IPv6 loopback
  dnl # device. Remove the loopback address restriction listen to the network.
  dnl DAEMON_OPTIONS(`port=smtp,Addr=::1, Name=MTA-v6, Family=inet6')dnl
  dnl # enable both ipv6 and ipv4 in sendmail:
  dnl DAEMON_OPTIONS(`Name=MTA-v4, Family=inet, Name=MTA-v6, Family=inet6')
  dnl # We strongly recommend not accepting unresolvable domains if you want to
  dnl # protect yourself from spam. However, the laptop and users on computers
  dnl # that do not have 24x7 DNS do need this.
  FEATURE(`accept_unresolvable_domains')dnl  //接受无法反向解析的域来的邮件
  dnl FEATURE(`relay_based_on_MX')dnl   //自动接受DNS中MX记录来源的邮件转发
  dnl # Also accept email sent to "localhost.localdomain" as local email.
  LOCAL_DOMAIN(`localhost.localdomain')dnl
  dnl # The following example makes mail from this host and any additional
  dnl # specified domains appear to be sent from mydomain.com
  dnl MASQUERADE_AS(`mydomain.com')dnl
  dnl # masquerade not just the headers, but the envelope as well
  dnl FEATURE(masquerade_envelope)dnl
  dnl # masquerade not just @mydomainalias.com, but @*.mydomainalias.com as well
  dnl FEATURE(masquerade_entire_domain)dnl
  dnl MASQUERADE_DOMAIN(localhost)dnl
  dnl MASQUERADE_DOMAIN(localhost.localdomain)dnl
  dnl MASQUERADE_DOMAIN(mydomainalias.com)dnl
  dnl MASQUERADE_DOMAIN(mydomain.lan)dnl
  MAILER(smtp)dnl
  MAILER(procmail)dnl
  dnl MAILER(cyrusv2)dnl
  ☆mc语法
一个mc模板文件通常可以包含几个段落:
  注意里面的正反引号,而且不能随便加入空格。
  sendmail宏定义说明
  divert(n) 为m4定义一个缓冲动作,当n=-1时缓冲被删除,n=0时开始一个新缓冲
  OSTYPE 定义宏所使用的操作系统,该宏允许m4程序增加同相关操作系统相关的文件
  Domain 定义MTA将使用哪些域来传输邮件
  Feature 定义配置文件中使用的一个特定的功能集
  Define 定义配置文件中的一个特定的选项值
  MASQUERADE_AS 定义sendmail来应答邮件的其它主机名
  MAILER 定义sendmail使用的邮件传输方法
  dnl 注释
  divert
  通常总是设置为divert(-1)让m4在输出中去掉一些垃圾。
  OSTYPE OSTYPE
  定义使用的操作系统类型,当然在我们的情况下就是linux,但是一定要注意m4程序中引号的用法,一个反引号和一个正引号才代表把对应的东西括起来。
  define
  定义一些全局设置,对于Linux系统,设置了OSTYPE之后,可以定义下面的一些全局 参数,如果不定义,就使用缺省值。例如:
  define(ALIAS_FILE,/etc/aliases)
  变量名 说明(方括号中为缺省值)
  ALIAS_FILE [/etc/aliases]
  别名文件的位置。如果有多个别名文件,需要把它们用引号括起来(别忘了引号规则 !)。
  confCR_FILE [/etc/mail/relay-domains]
  缺省的域定义文件,在这个域中定义的域中机器可以通过你的服务器进行邮件发送。
  HELP_FILE [/usr/lib/sendmail.hf]
  此文件中含有对SMTP的HELP命令进行响应时要列出的信息。
  QUEUE_DIR [/var/spool/mqueue]
  邮件队列文件所在目录。
  STATUS_FILE [/etc/sendmail.st]
  sendmail的状态信息文件。
  LOCAL_MAILER_PATH [/bin/mail]
  用于投递本地邮件的程序。
  LOCAL_MAILER_FLAGS [rmn9]
  local mailer要用到的标志,永远包含标志lsDFM。
  LOCAL_MAILER_ARGS [mail -d $u]
  在投递本地邮件时所传送的参数。
  LOCAL_MAILER_MAX [没有]
  如定义了此参数,则为此邮件服务器所能接收最大单个邮件大小。
  LOCAL_MAILER_CHARSET [没有]
  如果定义了此参数,则被转化为MIME格式的从其他地址到local mailer的含有8位字符 的信息将被标为此字符集。
  LOCAL_SHELl_PATH [/bin/sh]
  用于投递利用管道功能处理的邮件的shell.
  LOCAL_SHELL_FLAGS [eu9]
  prog mailer用到的标志。在此标志中永远包含标志lsDFM.
  LOCAL_SHELL_DIR [$z:/]
  shell运行时所要查找的目录路径。
  USENET_MAILER_PATH [/usr/lib/news/inews]
  用于投递电子新闻组的程序名称。
  USENET_MAILER_FLAGS [rlsDFMmn]
  usenet mailer的投递标志。
  USENET_MAILER_ARGS [-m -h -n]
  usenet mailer的命令行参数。
  USENET_MAILER_MAX [100000]
  usenet mailer所能接收的最大信息大小。
  SMTP_MAILER_FLAGS [没有]
  SMTP mailer附加标志。对所有基于SMTPmailer其默认标志为mDFMUX;基于esmtp的邮差 (mailer)加上a标志;而基于"smtp8"的邮差则加上8。
  SMTP_MAILER_MAX [没有]
  使用smtp,smtp8或esmtp传输的单个邮件最大容量。
  SMTP_MAILER_CHARSET [没有]
  如果定义了此参数,则被转化为MIME格式的从其他地址到任一个smtp mailer的含有8 位字符的信息将被标为此字符集。
  POP_MAILER_PATH [/usr/lib/mh/spop]
  pop邮差的路径名。
  POP_MAILER_FLAGS [Penu]
  pop邮差附加标志。同时总是加上标志lsDFM。
  POP_MAILER_ARGS [pop $u]
  传给pop邮差的参数。
  PROCMAIL_MAILER_PATH [/usr/local/bin/procmail]
  procmail程序的路径名。此外FEATURE(local procmail)也用到此参数。
  PROCMAIL_MAILER_FlAGS [SPhnu9]加给Procmail邮差的标志。同时总是加上"DFM"标志 。
  PROCMAIL_MAILER_MAX [没有]
  procmail所接收的最大单个邮件容量。如果你对某些人发送巨大的邮件感到困扰,启 用这个选项。
  FEATURE
  定义sednamil的一些运行参数,通常对我们来说最重要的一些选项是:
  use_cw_file
  读取文件/etc/sendmail.cw以确定这台机器应该替哪些机器接受邮件。此主机的别名 。当你使用 MX记录将此主机定义为其他主机的邮件交换机时需要使用这个特性。例如: FEATURE(use_cw_file)
  relay_hosts_only
  通常情况下,sendmail为sendmail.cf中明确列出的域(一般是localhost)和/etc/ mail/relay-domains中定义的域进行投递代理。缺省下这两处定义的都是域的名字。如果你定义了这个参数,那么这两处的内容将被解释为主机名字。
  use_ct_file
  读取文件/etc/sendmail.ct以取得系统"信任"的用户名字,这些用户可以使用-f设置其发信信封上的from地址而不产生警告信息。
  redirect
  使用REDIRECT特性,这个特性允许你对某些已经搬迁的用户发出重定向信息。(见下 一节)。
  例如:
  FEATURE(redirect)
  mailertable
  包含一个用于覆盖到特定域路由(routing)的"mailer table".此特性参数定义可以是 一个关键词定义。如未指定任何参数, 其定义通常是:
  FEATURE(mailertable,`hash -o /etc/mailertable)
  domaintable
  包含一个用于提供域名映象的"domain table",当改变你自已的域名时可能有用(如 你公司由oldname.com改为newname.com)。其定义通常是:
  FEATURE(domiaintable,`hash -o /etc/domaintable)
  always_add_domain
  在本地发送邮件时也加上其主机域名。例如:
  FEATURE(always_add_domain)
  allmasquerade
  如果使用了伪装(masquerading,使用MASQUERADE_AS),则此特性将使接收者的地址也伪 装为来自所伪装为主机。
  limitd_masquerade
  通常情况下$w所列出的所有主机将被伪装。如果使用了此特性,则只对那些$m所列出的主机进行伪装。
  masquerade_entire_domain
  如使用了伪装且设置了MASQUERADE_DOMAIN,此特性将引起 地址重写,使所要伪装的网 域整个被隐藏。所有含有被伪装域名的主机用伪装域名(通常是MASQUERADE_AS)进行重写 。
  masquerade_envelope
  用此特性告知sendmail将信封和信件头中上的发送者和接收者进行伪装。
  定义了有关masq的选项之后,就可以使用伪装了,可以直接将伪装命令写入mc模板, 示例如下:
  MASQUERADE_AS(masq.com)
  MASQUERADE_DOMAIN(foo.org)
  这意味着我们的someone@foo.org发信的时候,sendmail将会把它的信封伪装为some one@masq.com。这对于统一整个域的电子邮件是非常重要的。
  virtusertable
  允许在同一个主机上使用多个虚拟域。参考下一节。例如:
  FEATURE(`virtusertable,`hash -o /etc/mail/virtusertable)
  nullclient
  这是一个特殊情况--它生成一个除了支持将所有的邮件通过本地的基于SMTP的网络转 递到一个中心邮件HUB之外不含任何内容的配置文件。其参数是此邮件HUB的主机名。唯 一可与nullclient一起使用的其他特性是"nocanonify"(这样可以使非完全地址可通过S MTP连接进行发送;通常情况下地址将使用伪装名字转变为完全邮件名称,此伪装名字默 认值为邮件HUB主机的名字)。 在此特性使用是不应定义任何邮差。当然也不进行别名 处理或转寄。
  local_procmail
  使用procmail作为本地邮差。
  smrsh
  对到程序的邮件使用使用sendmail发行版所带的SendMail Restricted SHell (smrsh )而不是/bin/sh。由于sendmail是以root权限执行,某个发送到恶意程序的邮件可以破 坏系统,只要利用别名转向使得邮件被转发到对应的程序,因此缺省下sendmail用smrsh来处理邮件转发到程序的请求。这可以提高本地系统管理员控制对那些通过邮件运行程 序的行为,例如
  FEATURE(`smrsh,`/usr/sbin/smrsh)
  注意有些程序无法通过smrsh运行(例如majordomo的wrapper程序),这是出于安全 性的考虑,smrsh不准用户程序使用一些setuid功能。如果你一定要使用这些程序,清将 smrsh定义成其他shell程序,如sh。
  access_db
  本地存取控制文件的名字,缺省是/etc/mail/access.db,也可以用命令行指出,例 如:
  FEATURE(`access_db)
  或者 或者
  FEATURE(`access_db,`hash -o /etc/mail/access)
  mailertable
  允许使用mailertable文件。这个文件定义对某确定的域使用什么样的邮差。例如:
  FEATURE(`mailertable',`hash -o /etc/mail/mailertable)。
  blacklist_recipients
  允许你用前面定义的access_db来禁止某个地方来的邮件,或是某个人的邮件,等等 。
  relay_based_on_MX
  是否允许别人用你的机器当成MX交换器。如果你设置了这个选项,那么任何人只要在 域名服务器中将你的机器设置成为他的MX交换就可以用你的机器转发电子邮件。这个功 能意味着:你的机器替它接受电子邮件,再提交给它;一般来说这个功能是不必要的; 如果你一定要使用这个选项,记住你可能被庞大的邮件流量吞没。但是在一种情况下这 个功能又是不可缺少的:假如你的系统有防火墙,只有邮件服务器能够对外连接,那么 这个功能是使网络内部其他主机能够接受自己电子邮件的唯一方法。
  DOMAIN
  这个关键字一般用来定义邮件中继,假如你的系统里面除了Internet互连之外还有类似Decnet,UUCP之类的东西,那么你就需要设置DOMAIN来保证非internet的邮件被正确 中继。对于一般的系统,不需要定义这个属性。
  MAILER
  定义可以使用的投递程序(邮差)。
  例如:
  MAILER(smtp)
  定义smtp投递。
  MAILER(local)
  定义局部投递。
  如果你想做邮件服务,这样两个邮差是必须的。
  ☆sendmail.cf
#m4  sendmail.mc > /etc/sendmail.cf
  sendmail.cf语法复杂,内容繁多,它的配置信息和选项用于限定sendmail守护进程的运行。由于太复杂,很难逐条去建立它,而是通过用m4宏预处理器对
  有限而直观的.mc配置宏文件进行处理生成的。
  (1)sendmail.cf文件构成
  sendmail.cf文件由定义不同内容的多个小节构成,这些小节的作用见下表:
  小节
功能

Local Information
定义有关个人主机的信息

General Macros
定义有关本地网络的宏

Classes
定义用于特殊邮件传输程序的主机名群或域名群

Version Number
标识sendmail.cf文件的版本号

Special Macros
定义由sendmail所用的一些特殊的宏

Option
定义sendmail选项

Message Precedence
定义sendmail所用的各种消息的优先级值

Trusted Users
定义在发送邮件时可以忽略发送者地址的用户

Format of Headers
定义sendmail插入的邮件首部格式

Rewriting Rules
定义用于重写邮件地址的规则

Mailers
定义sendmail用来调用邮件传输程序的指令

Ruleset Zero
定义一组称为ruleset zero的重写规则

Machine-dependent part of Ruleset Zero
定义与配置相关的Ruleset Zero部分

  (2)sendmail.cf文件的命令
  sendmail.cf文件的每一行都以一个命令字符打头,后边是具体的设置内容。命令字符说明了本行的作用,设置内容说明了设置的对象,空行将被忽略。
  如果行的第一个字符是空格,说明是上一行的继续行。所有指令的意义如下:
  #:说明了本行是注释行;
  D:宏定义操作符;
  用法:DK [字符串],这就将宏K定义成了后面的字符串,可以在配置文件中对它进行引用,避免了多次输入某一相同的字符串。
  提示:宏的名字应该是单独的一个大写字母,因为sendmail用小写字母定义自己的宏变量。
  C和F:类定义操作符;
  用法:CK[类名]或者FK文件名,这就定义了类K或者定义了从指定的文件中读取类K的值。
  提示:一个类可以包含一个或多个单词,也要使用单独的大写字母,原因同上。
  H:邮件头定义操作符,一般不用对配置文件中缺省提供的邮件头做任何修改;
  O:设置选项操作符,sendmail具有多种可以设置其操作的选项,还可以通过这些选项来告诉sendmail,所要使用的文件放在什么位置。当然这些选项也
  可以通过命令行来提供,两种方法是等价的,人们常常将很少改变的设置在配置文件中通过O操作符给出;
  P:优先级操作符,用来指定邮件的优先级别。另外,sendmail还指定了一些具体的邮件标题,这些特定的邮件标题本身就具有了确定的优先级。例如:
  Pspecial-delivery = 100
  Pfirst-class = 0
  Plist = -30
  Pjunk = -100
  V:sendmail.cf的版本级别操作符,它能够使sendmail知道在配置文件中可以找到哪些特性;
  提示:sendmail.cf的版本级别和Sendmail的版本级别不是一回事。
  K:关键字数据库操作符,因为sendmail使用了一些关键字数据库,例如别名库等等。K操作符可以用来告诉sendmail这些可利用的数据库的位置或类别
  等类似信息,缺省支持DBM格式的库,一般可以支持DBM,BTREE,HASH,NIS等。
  M:邮件发送器的操作符,对于每一个目标,可以定义一个专门的邮件发送器。邮件发送器将通过定义在其中的sendmail固定的SMTP传输器,把邮件
  发送给其他主机。所有邮件发送器都是用M操作符和邮件发送器的名字开头的一行来定义,举例如下:
  Mlocal,  P=/bin/mail,  F=lsDFMfSn,  S=10,  R=20,  A=mail-d  $  u
  在上面本地邮件发送器的定义中:
  P操作项用来提供投递邮件的程序所处的位置的路径名称;
  F用来为本地邮件发送器提供sendmail标志;
  A项用来为运行的程序(这里是/bin/mail)提供命令行,所以sendmail将运行命令:mail-d $u,其中的宏$u将被替换为邮件应该被发送的用户的用户名。
  S和R是规则集操作符。规则集用来发现地址中的错误,将地址改写为远程邮件发送器能够理解的形式,以及将邮件解析到sendmail内部的某个邮
  件发送器。sendmail将按固定的顺序向规则集传送地址,规则集也可以调用其他的规则集。规则集由S来指定,S的后面
  是用来表示规则集的编号。
  (3)sendmail.cf中的预定义宏
  sendmail.cf中的预定义宏参见下表:
  
  宏名
意义

a
RFCs822格式的原始日期

b
RFCs822格式的当前日期

c
Hop计数

d
UNIX格式的日期

e
SMTP数据项信息

f
邮件发送者地址

g
相对于接收者的发送者地址

h
接收主机

i
队列标识

j
节点的正式域名

l
UNIX的行格式

n
用于错误信息中的名字

o
地址中的操作符集合

p
sendmail的PID

q
默认的发送者格式

r
所用的协议

s
发送者的主机名

t
当前时间的数值表示

u
接收方用户

v
sendmail的版本号

w
该节点的主机名

X
发送者全名

z
接收者主目录

  ☆acces                                                        
限制某些域的邮件,/etc/mail/access访问控制列表设置文件的格式是这样:
  [地址] [操作]
  中间的分割符是空格键。
  [地址]栏 可以是主机地址或者名字,也可以是统配符,规则是这样:
  yourdomain.com :代表所有*.yourdomain.com的名字。
  192.168.12   :代表所有192.168.12.*的地址。
  202.135  :代表所有202.135.*.*的地址。
  someone@somedomain.com  :代表一个特定的邮件发信人
  [操作]栏通常有:
  OK       :正常接受这封邮件,远程主机可以向你的邮件服务器发送邮件;
  RELAY   :允许SMTP代理投递,这样这封邮件就可以从你的机器中转到别的机器上去; 例如:127.0.0.1  RELAY
  192.168.10  RELAY
  表示允许本机和192.168.10.0网段中的机器通过该邮件服务器转发邮件。
  REJECT  :拒绝接受,不能向你的邮件服务器发邮件和不能中转;
  DISCARD :发来的邮件将被丢弃,同时并不向发送者返回错误信息。忽略这封邮件,这种情况下,邮件看上去是正常投递了,但是由
  于没有人接受,邮件会自动地"消失"在网络中。
  nnn text--  :发来的邮件将被丢弃,但sendmail将会向发送者返回nnn确定的smtp代码和text变量确定的文本描述。
  错误代码+任何其他字符串:将向发信者返回这个字符串作为出错信息。错误代码是RFC 822定义的标准出错代码。例如
  550 We don like a spammer!。客户机器在投递邮件的时候,就会产生一个"we don like a spammer"投递失败信
  息。比如,你认为someone@spammer是个专门投递垃圾邮件的家伙,那么你可以这样写:
  someone@spammer 550 we don like a spammer ,然后重新启动sendmail就可以使用这些功能了。
  
  
  
  192.168  RELAY
  panda.NET  OK
  panda.COM  REJECT
  panda.COM  550  SORRY,WE DON'T ALLOW SPAMMERS HERE
  panda.ORG  DISCARD
  
  设置完成后要用#makemap  hash  access.db < access命令生成数据库。
  ☆access.db
一般/etc/mail/access.db是一个散列表数据库,它是用/etc/mail/access为模版产生出来的。
  ☆aliases
/etc/aliases,这个文件用来设置用户的别名。文件/etc/aliases允许为本地用户,应用程序,甚至其他别名提供虚拟邮箱:
  aliases文件的格式是
  邮件别名:实际用户名
  如果一个别名有多个用户就用逗号分开 ,每个别名一行。
  1.最简单的情况是需要作信件分发的情况:
  要把发给postmaster的信件发送给supervisor和manager,需要写上这样一行:
  postmaster:supervisor,manager
  别名还可以用在这样的情况,即定义自动的邮件转发。
  某个用户以前在你的系统上接受电子邮件,现在他有了一个新的电子邮件,希望发到你的机器上的邮件自动被转发到他新的电子邮件地址上,那么,可以使用类似这样的别名方式:(假设你的机器是 panda@panda.com)
  panda:epeppanda@hotmail.com
  以后发给panda@panda.com的电子邮件就自动中转到epeppanda@hotmail.com。注意左边自动加上你的机器名字,所以左边只能是账号名字,不能是全限定邮件地址。
  2.别名的右侧也可以是文件或程序。
  上面的postmaster别名可以用这样方法来设置:
  panda: :include: /etc/mail/myaliases
  include:关键字表示让sendmail去读取对应的包含文件。而/etc/mail/myaliases的内容要设置成:
  pandeng
  manager
  3.要把邮件重定向到程序,可以使用管道
  panda:"|/home/panda/testpg"
  那么,sendmail会将发给panda的邮件的内容作为/home/panda/testpg程序的输入来执行这个程序。
  另一个常用的办法是重定向。如果你在模板文件中定义了REDIRECT特性,那么可以使用这个功能。
  某个人在你的机器上开了一个账户user1,后来迁移到user2@server2.com。那么,你可以将其别名写成
  user1: user2@server2.com.REDIRECT
  以后当有人向这个地址发信的时候,你的sendmail会将其退回,并且返回一个551 User not local; please try user2@server2.com的信息。
  在使用别名的时候,必须注意的是不要造成循环,例如user1转发给user2,user2又将 其转发给user1....如此循环。在这种情况下,转发17次后,sendmail将把它退还给发信 人。最常见的错误发生在你试图在转发邮件的同时在本地保留备份的情况下,例如:
  user1: user1,user2
  就构成了一个循环。
  在修改了别名文件之后,重新初始化别名数据库:
  [iyunv@mail mail]# newaliases
  /etc/aliases: 17 aliases, longest 31 bytes, 241 bytes total
  也可以使用sendmail -bi命令:
  [iyunv@mail mail]# sendmail -bi
  /etc/aliases: 17 aliases, longest 31 bytes, 241 bytes total
  两种方式实际是完全一样的。
  当前版本的sendmail对各种附加文件和配置文件的属性都有着严格的要求,特别是/etc/aliases文件,必须至少为0644以避免非授权的修改。
  ☆.forward
  ~/.forward
  其实该文档的作用和aliases数据库的作差不多啦,都是配置别名,做邮件转发的。因为alises只能由管理员控制,个人用户不能修改,所以就可以在test个人的目录下建立一个转寄文档。以设置个人的邮件转寄列表。文档格式如下:
  test
  test1
  test2
  test3
  user2@domain.com
  ......
  这种技术可以让每个用户自己管理自己的邮件别名。但由于个人用户安全意识差,如果设置不当会有安全漏洞,不建议使用。
  ☆local-host-names
/etc/mail/local-host-names
  将FEATURE(use_cw_file)包含在你的sendmail.mc文件当中,Sendmail将用本地主机名来作为你的本地别名。
  主机别名文件
  它给出本地主机的别名。如果你的主机有多个名字,或者你的主机是整个域的信件交换主机,你就需要这个文件了。
  # local-host-names - include all aliases for your machine here.
  panda.com
  www.panda.com
  mail.panda.com
  otherdomain.com
  如果Sendmail没有在收件列表中发现相应的主机名,它将拒绝接受对方发来的邮件。
  如果你有多个别名或者需要负责的交换域,每个需要单独写上一行。
  请记住在修改了这个或其他任何配置文件后你必须重启Sendmail。
  
  
  ☆trusted-users
设置可信任用户
  可以代表其他用户发邮件的用户
  这个可选的特性在sendmail.mc中的名称为use_ct_file。
  这个列表中的用户可以改变电子邮件的寄件人。
  在/etc/mail/trusted-users文件中每个用户名占一行。
  这对运行在你的服务器上的脚本或应用程序给某个人或组发信息是非常有用的。
  它可以更容易的快速识别一个电子邮件的信息。
  ☆virtusertable
改域名后,可以做域名的转换 旧域 新域
  类似于aliases文件,但用于外部用户
  /etc/mail/virtusertable
  虚拟用户表格向你服务器上的真实邮箱发送虚拟域和邮箱的邮件。这些邮箱可以是本地的,远程的,或是由/etc/aliases定义的别名。这些是在你的sendmail.mc文件中一命令行的形式进行初始配置的。
  语法如下:
  左地址 右地址
  中间用Tab键分开。
  例如: someone@otherdomain.com  localuser
  这样一行意味着本来应该发送给someone@otherdomain.com的邮件现在要发送给本机的用户localuser。当然,这意味着:第一,你的DNS记录中,本机应该是otherdomain.com的MX交换器;第二,你的本机local-host-names文件应该包含otherdomain.com这个名字。
  当然纯粹的这样的域意义不大,但是sendmail还支持邮件虚拟域的参数翻译。例如:
  @testdomain.com  test@mydomain.com
  意味着所有发往xxx@testdomain的邮件都会被发送到test@mydomain.com。而
  @testdomain.com  %1test@mydomain.com
  则代表参数转义,例如user1@testdomain.com的邮件被发送到user1test@mydomain.com,user2@testdomain.com被发送到user2test@mydomain.com。同样,这样的功能也要通过MX记录和local-host-names文件加上去。
  建立virtusertable的方法与建立access的办法是一样的:
  #makemap  hash  virtusertable.db < virtusertable
  然后重新启动sendmail。
  ☆virtusertable.db
如同Apache一样,sendmail也允许使用虚拟主机功能,这是通过FEATURE(virtusertable)功能实现的,而虚拟主机的文件缺省是/etc/mail/virtusertable.db,它用/etc/mail/virtusertable文件生成,这个文件的形式类似于aliases文件,
  #makemap hash virtusertable.db < virtusertable
  ☆mailertable
定义邮差
  /etc/mail/mailertable文件(在FEATURE(`mailertable')里定义)用来定义对某个域名或者用户使用什么样的邮差,如sz.st-anda.com smtp:[10.100.100.252]等等。一般情况下,并不需要定义这个功能。建立这个文件的方式与上面的几个hash数据库相同。
  ☆spamassassin
给/etc/procmailrc增加:
  INCLUDERC=/etc/mail/spamassassin/spamassassin-default.rc
  来支持SpamAssassin
  ☆statistics
/var/log/mail/statistics
  用mailstats来读取这个文件,主要记录sendmail收发信件的相关信息。
  ☆submit.mc
可以让使用sendmail的限定于组
  ☆Makefile
/etc/mail/Makefile中是编译选项,用make -C /etc/mail来处理mail目录中的所有文件
  ☆mqueue
/var/spool/mqueue是邮件队列临时存放的目录。在/var/spool/mqueue下,有不同的队列。消息存放在不同的队列中。消息队列文件有以下形式: qf* ------消息队列控制文件          df* ------数据文件        tf* -------临时文件
  nf* -------每个用户对应的消息队列   xf* ------当前会话过程的transcript文件
  一般来说,sendmail守护子进程周期性地处理此队列,尝试发送每个消息。//etc/init.d/sendmail脚本启动sendmail进程,使它每15分钟fork出一个子进程,来处理这个mail队列,每次sendmail处理这个队列的时候 ,它就读取此队列并排序,然后试图依次运行各个任务。
  15              ☆mail日志
Sendmail很好的利用的它的日志文件,你可以追捕到大部分问题的所在。
  mail.log和mail.err是你需要注意的两个主要文件,还有就是mail.warn和mail.info。
  这些文件有许多共同之处,所以我一般只看前两个文件。一般而言,你可以在 /var/log/下找到这些文件,对特定的系统和Linux版本,可能在其他目录下。如果必要的话,你可以察看/etc/syslog.conf文件。典型的电子邮件成功发送一般是这样的:
  Oct 25 18:22:14 example sendmail[29322]: SAA29322: from=user, size=193, class=0, pri=60193, nrcpts=2, msgid=<200110260122.SAA29322@panda.com>, relay=user@local
  Oct 25 18:22:14 example sendmail[29324]: SAA29322: to=help@techsupport.net, ctladdr=user (500/1000), delay=00:00:00, xdelay=00:00:00, mailer=local, stat=Sent
  你可以在mail.log看到和下面类似的拒绝信息:
  Oct 23 14:23:51 example sendmail[27467]: OAA27467: ruleset=check_rcpt, arg1=, relay=west1.mail-abuse.org [204.152.186.193], reject=550 ...  Relaying denied
  通常,你所需要的所有信息都存储在这些日志文件中,包括用户名,主机名,出错代码。这些出错代码很有用处,可以通过这些让你对自己有更好的了解。
  #tail  -f  /var/log/maillog  使用tail的-f命令可以观察日志文件内容的实时更新,特别适合于对服务器进行调试和错误检查。
  16              ☆Sendmail的常见配置举例
假设配置的要求如下:
  ·邮件服务器的IP地址为192.168.1.2,主机域名为mail.1test.com
  ·邮件服务器将为1test.com域中的用户提供邮件服务
  ·为了防止垃圾邮件,服务器需要具有SMTP用户认证功能
  邮件服务器的基本配置步骤:
  1.首先一定要安装以下两个软件包,否则m4,newaliaes,makemap命令都无法使用:
  #rpm  -ivh  sendmail-cf-8.13.8-2.el5.i386.rpm      (第二张光盘,默认未装)
  #rpm -ivh  sendmail-doc-8.13.8-2.el5.i386.rpm (第三张光盘,默认未装)
  2.域名设置
  邮件服务器的正常工作需要在DNS服务器中进行相应的设置,对于主机域名为mail.1test.com的邮件服务器需要在1test.com域的主DNS服务器中进行设置:
  mail   IN   A   192.168.1.2
  @      IN   MX   5    mail.1test.com.  
  3.设置local-host-names文件
  在sendmail服务器的配置目录下,local-host-names文件用于设置邮件服务器提供邮件服务的域名。例如,为了对1test.com域提供邮件服务,local-host-names
  文件中需要添加1test.com设置行。
  #vi /etc/mail/local-host-names
  1test.com      //添加邮件服务器提供邮件服务的域名
  在local-host-names文件中设置域名后,sendmail服务器将对文件中设置的域名提供邮件服务。
  4.开启sendmail服务器的网络接口
  sendmail服务器出于安全考虑,默认只对lo回环网络接口(IP地址为127.0.0.1)提供服务,为了使服务器能够为主机的所有网络接口(地址为0.0.0.0)提供服务
  需要在sendmail.mc文件中进行配置的修改:
  #vi /etc/mail/sendmail.mc
  DAEMON_OPTIONS('Port=smtp,Addr=127.0.0.1,Name=MTA')dn1    //查找到此行,修改为:
  DAEMON_OPTIONS('Port=smtp,Addr=0.0.0.0,Name=MTA')dn1
  在sendmail.mc文件中进行以上修改后,sendmail服务器将监听主机所有网络接口的25端口。
  5.sendmail服务器的用户管理
  (1)设置SMTP的用户认证
  邮件服务器提供发送邮件的功能是很正常的,但是如果为所有人都能够无条件地发送(投递)邮件是很危险的,非常容易造成大量垃圾邮件产生。因此在sendmail
  服务器中需要设置发送邮件的用户认证,当用户使用MUA软件通过SMTP向邮件服务器发送邮件时,邮件服务器会要求用户提供用户账号和口令进行身份认证,只有
  通过身份认证的用户才能通过邮件服务器向外部发送邮件。RHEL5系统中提供的sendmail服务器提供了SMTP的用户认证功能,但是默认的设置没有启用此功能,因
  此需要在sendmail.mc文件中进行相应的配置:
  #vi /etc/mail/sendmail.mc
  dnl TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl  //查找到以下两行
  dnl define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
  修改为:
  TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl  //去掉前面的注释字符串dnl
  define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl   //去掉前面的注释字符串dnl
  特别注意:以上两行去掉了前面的注释串dnl后,前面一定不能留有空格,否则在启动sendmail服务时会出错!
  在sendmail服务器中,使用了sasl的第二版sasl2作为SMTP的认证方式,在/usr/lib/sasl2/Sendmail.conf配置文件中设置了使用saslauthd服务程序提供用户认
  证服务,因此当sendmail服务器使用SMTP认证功能时,需要确保saslauthd服务程序正确运行:
  #cat  /usr/lib/sasl2/Sendmail.conf
  pwcheck_method:saslauthd
  #chkconfig  --level 35  saslauthd on
  #service saslauthd start        
  (2)用户账号
  sendmail服务器使用linux系统中的用户账号作为邮件账号,因此为用户添加邮件账号只需要添加linux用户账号即可。为了便于对邮件用户进行管理,需要先建
  立邮件用户组mailuser,新建立的邮件用户账号应属于该组账号。由于邮件账号通常不需要登录linux系统,因此在adduser命令中可以使用“-s”选项指定用户
  的shell为“/sbin/nologin”,即不允许用户登录linux系统。在建立邮件用户账号之后,需要使用passwd命令为用户设置口令,以便用户发送和收取邮件时进
  行身份认证。
  #groupadd mailuser       //建立邮件用户组mailuser;
  #adduser -g  mailuser -s  /sbin/nologin  name1    //创建邮件用户账号name1和name2;
  #adduser -g  mailuser -s  /sbin/nologin  name2
  #passwd name1           //设置邮件用户口令
  #passwd name2
  (3)设置邮件别名和邮件群发功能
  在sendmail服务器中使用aliases机制实现邮件别名和邮件群发功能,在“/etc”目录下同时存在名为aliases和aliases.db两个文件。aliases文件是文本文
  件,其内容是可阅读和可编辑的,aliases.db是数据库文件,是由aliases文件生成而来的。对“/etc/aliases”文件的内容进行修改后,需要执行newaliases
  命令,该命令根据aliases文件的内容重新生成aliases.db文件。只有对aliases.db文件进行了更新,aliases文件中新的别名设置在系统中才会生效,在aliases
  文件中每行作为一个别名设置记录,记录的格式如下:
  name: addr_1, addr_2, addr_3,...addr_N
  在aliases记录的格式中name表示虚拟邮件账号,addr_N表示真实邮件账号名,aliases记录可实现邮件别名和邮件群发功能。在RHEL5系统的“/etc/aliases”
  文件中已经默认设置了一些别名记录,其中大部分都是为root用户设置的别名。
  例1.为邮件用户name1设置别名admin的记录如下:
  #vi /etc/aliases
  admin: name1
  #newaliases
  sendmail服务器会根据设置的别名记录将发往admin用户的所有邮件转发到name1用户的邮箱中,即实现了为name1用户设置别名。
  例2.设置别名记录,将发往testgroup邮箱的所有邮件都转发到name1和name2用户的邮箱中,实现邮件的群发功能:
  #vi /etc/aliases
  testgroup: name1, name2
  #newaliases
  为了实现邮件群发功能,需要在别名记录中设置多个真实邮件账号的名称。
  
  
  
  
  6.访问控制的设置
  在sendmail服务器中使用access.db数据库进行基于主机地址的访问控制,默认开启了对邮件服务器本机用户的邮件投递,即在sendmail服务器所在主机中的用
  户可以任意发送邮件,而不需要进行任何身份认证。
  #vi /etc/mail/access
  localhost.localdomain    RELAY
  localhost                 RELAY
  127.0.0.1                 RELAY
  access.db数据库文件和SMTP认证功能配合使用,可以保证sendmail服务器具有较好的安全性。
  7.生成sendmail.cf文件
  在对sendmail.mc文件修改完成了所有的配置后,需要使用m4命令生成新的sendmail.cf配置文件:
  #cd /etc/mail
  #m4  sendmail.mc > sendmail.cf
  注意:m4命令一定要在/etc/mail目录下执行!
  8.重新启动sendmail服务器
  当完成对sendmail服务器的配置之后,需要使用sendmail脚本重新启动服务程序,使新的配置生效:
  #service  sendmail  restart
  使用netstat命令可以查询到sendmail服务程序已经对所有的网络接口的25端口进行了邮件服务的监听:
  #netstat -ntpl  | grep 25
  通过telnet邮件服务器的25端口可以验证邮件服务器的SMTP认证功能:
  #telnet  localhost  25
  .......
  ehlo  localhost  //登录到邮件服务器的25端口后,输入ehlo localhost命令会显示邮件服务器的状态信息;
  ........
  250-AUTH  DIGEST-MD5 CRAM-MD5 LOGIN  PLAIN   //如果在250-AUTH开始的行中出现了LOGIN PLAIN,则说明sendmail服务器中设置的SMTP认证功能生效。  
  通过telnet命令与SMTP服务交互通信的步骤,演示SMTP的工作过程:
  (1)客户机通过telnet命令与服务器的25端口建立一个TCP连接,连接成功后,服务器返回一个表示通信连接成功的220应答代码:
  #telnet  localhost  25
  220 localhost.localdomain ESMTP Sendmail 8.13.8/8.13.8;Sun, 5 0ct 2008 04:14:52 +0800
  (2)发送HELO,向服务器标识发件人的身份,若成功,则会收到表示邮件系统命令成功的250应答码:
  HELO localhost    //输入此语句
  250  localhost.localdomain Hello localhost.localdomain [127.0.0.1],pleased to meet you
  (3)使用MAIL FROM:命令给服务器传送发信人地址,传送成功后,收到250应答码:
  MAIL FROM:tjj@benet.com    //输入此语句
  250 2.1.0 tjj@benet.com......Sender ok
  (4)使用RCPT TO:命令传送收信人地址,可以传送多行收信人地址到服务器,服务器收到有效的收信人地址后,将返回250成功应答码:
  RCPT TO:root     //输入此语句
  250 2.1.5 root.....Recipient ok
  (5)向服务器发送DATA命令,准备开始传送邮件内容,服务器若返回354应答码,即表示已经准备接收邮件内容,可以在下一行开始输入邮件内容,并在最后一行,
  以只含一个圆点的行表示输入结束(即在新行中键入圆点字符,然后回车,将结束邮件内容的输入)。服务器接受输入后,返回250应答码,开始传送邮件:
  data           //输入此语句,准备开始传送邮件内容
  354 Enter mail ,end with "." on a line by itself
  I love your ,LINUX!    //此行开始输入邮件内容
  .              //结束行中只输入一个圆点表示将结束邮件内容的输入
  250 2.0.0 m94KG5YI029186 Message accepted for delivery   
  (6)使用QUIT命令退出通信过程,相应的用户将会收到该信件:
  QUIT      //表示退出通信过程
  221 2.0.0 localhost.localdomain closing connection
  Connection closed by foreign host.
  邮局的基本配置步骤:
  在整个邮件系统中sendmail服务器实现了SMTP功能,因此只实现了邮件的发送功能,并不为MUA软件提供收取邮件的功能,收取邮件需要单独安装实现POP3或IMAP
  功能的服务器程序,可以使用dovecot服务器实现POP3功能。
  1.安装dovecot软件包
  由于安装dovecot服务器依赖的软件包较多,建议使用RHEL5系统的软件包管理程序来安装docecot软件包:#system-config-packages,或依次安装以下rpm包:
  #rpm  -ivh  perl-DBI-1.52-1.fc6.i386.rpm   (第二张光盘)
  #rpm -ivh   mysql-5.0.22-2.1.i386.rpm     (第二张光盘)
  #rpm -ivh  dovecot-1.0-1.2.rc15.el5.i386.rpm  (第二张光盘)
  若是RHEL4系统则需依次以下包:
  #rpm -ivh  perl-DBI-1.40.5.i386.rpm --aid    (第二张光盘)
  #rpm -ivh  perl-DBD-MySQL-2.9004.3-1.i386.rpm --aid  (第二张光盘)
  #rpm -ivh  mysql-4.1.7-4.RHEL4.1.i386.rpm   (第二张光盘)
  #rpm -ivh  postgresql-libs.7.4.6-1.RHEL4.2.i386.rpm  (第二张光盘)
  #rpm -ivh  dovecot-0.99.11-2.EL4.1.i386.rpm        (第四张光盘)
  2.设置dovecot服务器
  dovecot服务器的配置文件是/etc/dovecot.conf,dovecot服务器可以提供IMAP和POP3服务,但是默认只提供IMAP服务,因此需要在/etc/dovecot.conf配置
  文件中进行设置的修改:
  #vi /etc/dovecot.conf
  #protocols = imap imaps  //修改此行,去掉注释“#”;添加pop3,pop3s两项服务
  修改为:
  protocols = imap imaps pop3 pop3s
  3.启动dovecot服务程序,并设置启动状态
  对dovecot.conf配置文件进行设置后,需要重新启动dovecot服务程序,以便新的设置生效,而且dovecot服务程序安装后默认设置并不自动启动,所以需要使用
  chkconfig命令设置自动运行,以保障邮件服务器的正常运行:
  #service dovecot restart
  #chkconfig --level 35  dovecot on
  #netstat -ntpl | grep 110
  
  
  17              ☆sendmail校验
看sendmail是否启动:
  #netstat -nutlp | grep :25
  确定sendmail没有在启动的时候出现错误,/var/log/maillog中。检查此文件中的最后出现"starting"的地方以确保sendmail在启动的时候没有任何错误。
  sendmail可执行文件位于/usr/sbin/sendmail,为了确定sendmail是否正确标识您的主机名称,通过命令行开关开启其调试模式并且设定为0:
  [iyunv@panda mail]# sendmail -d0 < /dev/null
  Version 8.13.1
  Compiled with: DNSMAP HESIOD HES_GETMAILHOST LDAPMAP LOG MAP_REGEX
  MATCHGECOS MILTER MIME7TO8 MIME8TO7 NAMED_BIND NETINET NETINET6
  NETUNIX NEWDB NIS PIPELINING SASLv2 SCANF STARTTLS TCPWRAPPERS
  USERDB USE_LDAP_INIT
  ============ SYSTEM IDENTITY (after readcf) ============
  (short domain name) $w = panda
  (canonical domain name) $j = panda.panda.com
  (subdomain name) $m = panda.com
  (node name) $k = panda
  ========================================================
  Recipient names must be specified
  如果sendmail返回您的主机名称为localhost,您可能错误配置了/etc/hosts文件。检查您的/etc/hosts文件,删除所有的但记住留下localhost的指向。
  127.0.0.1   panda.panda.com   panda   localhost
  如果/etc/hosts文件是正确的,那么检查一下在/etc/sysconfig/network中的HOSTNAME的定义。
  试图向root@panda发送简单的邮件。您可以看到一个合理的您的主机的转发服务器的SMTP交换。
  echo "hello root" | mail -v -s hello root@panda
  [iyunv@panda ~]# echo "hello root" | mail -v -s hello root@panda
  root@panda... Connecting to [127.0.0.1] via relay...
  220 panda.panda.com ESMTP Sendmail 8.13.1/8.13.1; Thu, 27 Jul 2006 08:46:11 +0800
  >>> EHLO panda.panda.com
  250-panda.panda.com Hello panda.panda.com [127.0.0.1], pleased to meet you
  250-ENHANCEDSTATUSCODES
  250-PIPELINING
  250-8BITMIME
  250-SIZE
  250-DSN
  250-ETRN
  250-AUTH DIGEST-MD5 CRAM-MD5
  250-DELIVERBY
  250 HELP
  >>> MAIL From:<root@panda.panda.com> SIZE=42 AUTH=root@panda.panda.com
  250 2.1.0 <root@panda.panda.com>... Sender ok
  >>> RCPT To:<root@panda.panda.com>
  >>> DATA
  250 2.1.5 <root@panda.panda.com>... Recipient ok
  354 Enter mail, end with "." on a line by itself
  >>> .
  250 2.0.0 k6R0kBQO005444 Message accepted for delivery
  root@panda... Sent (k6R0kBQO005444 Message accepted for delivery)
  Closing connection to [127.0.0.1]
  >>> QUIT
  221 2.0.0 panda.panda.com closing connection
  You have mail in /var/spool/mail/root
  如果SMTP交换向上面一样正确,那么消息将被转发到您的工作站上的本地的转发服务器上,并且mailq -Ac将会报告一个空的对列。接下来检查mail(不使用参数)来检查一下消息是否从本地的转发到server1。这样对列也应该是空的。
  [iyunv@panda public_html]# mailq -Ac
  /var/spool/clientmqueue is empty
  Total requests: 0
  您的消息是不是在/var/log/maillog中正确的记录呢?在下面的步骤中,监视文件/var/log/maillog。下面的命令将会十分的有用:
  #xterm -e tail -f /var/log/maillog &
  18              ☆sendmail收取邮件
为了安全的原因,sendmail和postfix的缺省的配置允许发邮件但是不允许从网络上接收邮件(缺省的它们只接受从回环接口上的连接)。
  确保在Server上的sendmail.mc文件中的DAEMON_OPTIONS被注释并且重新编译sendmail.cf文件使得能构接受来自其他主机的电子邮件。
  修改 /etc/mail/sendmail.mc
  使用dnl注释在下面的行之前,就象这样:
  dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')
  先将您的sendmail.cf文件做一个备份:
  cp /etc/mail/sendmail.cf /etc/mail/sendmail.cf.bak
  在同一个目录下,编译sendmail.cf
  m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
  重新启动sendmail
  19              ☆sendmail别名
sendmail的主要的别名配置文件是/etc/aliases。
  在sendmail决定消息的接受者的目的地的之前,其先试图在别名中查找。
  为了优化查找,sendmail为其别名记录建立了一个哈希表数据库/etc/aliases.db该文件通过newaliases命令产生(该命令是sendmail -bi的同名)
  下列命令将增加用户student(如果不存在的话)
  useradd student
  在/etc/aliases 行加入如下的行:
  me: student(别名:实际用户名)
  wizards: root, me
  methere: student@panda.panda.com
  现在运行
  newaliases
  命令来更新数据库
  尝试发送邮件给您定义的收件人:
  echo "hello there" | mail -s "hello" me
  echo "hello there" | mail -s "hello" wizards
  echo "hello there" | mail -s "hello" methere
  您是否得到了期望的结果?是否所有的位于wizards的收件人都受到了邮件?如果没有,su - 到不是root的用户再试一次。
  如果没有收到,可能需要在/etc/mail/access中打开权限
  20              ☆sendmail允许转发
通过控制您的机器的混杂转发,您可以使得任何人都能够将您的机器作为转发的主机。
  配置/etc/mail/sendmail.mc, 通过加入如下行使得m4前置处理器允许混杂转发(可以发到任何地址):
  /etc/mail/sendmail.mc中添加
  FEATURE(`promiscuous_relay')dnl
  使用m4前置处理机通过这个模板文件生成一个新的sendmail配置文件,然后将新生成的文件与通过sendmail RPM软件包提供的进行比较
  m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.relay
  diff /etc/mail/sendmail.relay /etc/mail/sendmail.cf
  使用混杂转发以后会有多大的不同呢?现在将新建立的sendmail.relay放置在恰当的位置上,重新启动sendmail.
  mv /etc/mail/sendmail.cf /etc/mail/sendmail.cf.accept-mail
  cp /etc/mail/sendmail.relay /etc/mail/sendmail.cf
  service sendmail restart
  让您的伙伴扮演恶意的垃圾邮件的发送者,该人能够通过telnet到您的机器上的smtp(sendmail)的25号断口,进行垃圾邮件发送地址的欺骗,在panda主机上键入如下命令:
  [iyunv@panda ~]# telnet panda 25
  Trying 127.0.0.1...
  Connected to panda.panda.com (127.0.0.1).
  Escape character is '^]'.
  220 panda.panda.com ESMTP Sendmail 8.13.1/8.13.1; Thu, 27 Jul 2006 01:12:37 +0800
  helo panda.panda.com
  250 panda.panda.com Hello panda.panda.com [127.0.0.1], pleased to meet you
  mail from: panda@panda.panda.com
  250 2.1.0 panda@panda.panda.com... Sender ok
  rcpt to:root@panda.panda.com
  250 2.1.5 root@panda.panda.com... Recipient ok
  data
  354 Enter mail, end with "." on a line by itself
  Subject: Faked
  this was faked!
  250 2.0.0 k6QHCb8x007709 Message accepted for delivery
  quit
  221 2.0.0 panda.panda.com closing connection
  Connection closed by foreign host.
  垃圾邮件现在送到您的机器上了。下一步,发给其他主机
  21              ☆sendmail不允许转发
通过替换新的sendmail.cf为接受传入的信件的配置文件来恢复缺省的sendmail的配置,并且重新启动sendmail:
  注释掉这行
  FEATURE(promiscuous_relay)dnl
  mv /etc/mail/sendmail.cf.accept-mail /etc/mail/sendmail.cf
  service sendmail restart
  让您的伙伴再从stationY转发垃圾邮件。您的sendmail还是一个转发器么?任何一个转发的都会产生如下的消息:
  550 5.7.1 kddk@kdk.com... Relaying denied
  但是本机是可以转发的(access文件中定义)
  22              ☆sendmail选择性的转发
对于特定的主机,域或者网络,编辑/etc/mail/access并且重新启动sendmail。
  为了允许所有在panda.com域中的机器可以把您的机器作为邮件转发服务器,你在/etc/mail/access中添加如panda.com域。
  然后用#makemap hash access.db<access
  23              ☆m4
sendmail是一个极为复杂的程序,其行为主要地依赖于在UNIX界"臭名昭著"的/etc/sendmail.cf配置文件。实际上,我怀疑会有谁真的从头去写一个sendmail.cf文件。一般来说,我们总是用m4宏处理来书写sendmail.cf。实际上,m4程序几乎和sendmail.cf一样复杂,不过,通常我们只需要关心一些比较重要的部分。
  要使用宏处理程序,必须确定你已经安装了m4和sendmail-cf这样两个软件包
  用m4程序可以生成一个sendmail.cf:  #m4 sendmail.mc > /sendmail.cf
  24              ☆sendmail总结
配置接收邮件,/etc/mail/sendmail.mc
  dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')
  m4 sendmail.mc > sendmail.cf
  添加别名 在/etc/aliases加入别名,newaliases
  不充许转发:默认
  转发:在sendmail.mc 加入
  FEATURE(promiscuous_relay) dnl
  选择转发: /etc/mail/access
  用户和主机访问控制
  /etc/mail/access
  domain.com RELAY
  USER@ REJECT
  USER@domain.com REJECT
  IP RELAY
  makemap hash access.db<access
  或
  makemap hash access <access .db可以省略
  25              ☆新建E-Mail帐号
在LINUX中,要为一个新的用户开E-Mail帐号是十分简单的。只要在LINUX系统中新增一个用户就可以了。那么这个用户帐号和密码就是E-Mail的帐号和密码。
  我为一个新用户test开一个E-Mail帐号。就用以下命令:#adduser panda, # passwd panda
  这样,这个新用户的E-Mail地址就是: panda@panda.com 密码当然就是帐号的密码了。
  要防止本地用户利用 sendmail 服务器上的漏洞,最好是让邮件用户只使用电子邮件程序来访问 sendmail 服务器。邮件服务器上的 Shell 帐号不应该被允许,/etc/passwd 文件中的所有用户 shell 都应该被设置为 /sbin/nologin,在添加系统用户时可以useradd -s /sbin/nologin 用户名,这样添加的用户名就没有了shell,只能收发信而不能登陆到服务器运行其他程序,安全一点。
  26              ☆sendmail邮件限额
当一个E-Mail服务器为许多人提供E-Mail服务的时候,无限量的电子邮件将很容易塞满服务器的硬盘,造成很大的负载。如果你的服务器不想为用户提供无限空间的E-Mail暂存空间,那么你就可以使用"邮件限额"来给用户一个有限的暂存空间。
  其实,它是利用磁盘限额功能来实现的。电子邮件的暂存空间是在/var/spool/mail目录下,只要通过磁盘限额设定每一个用户在这个目录下能使用的最大空间就可以了。
  27              ☆mailstats
邮寄状态查询命令,可查询sendmail运行作至今邮件收发总计资料。
  M :
  msgsfr:发送的邮件数量
  bytes_from:邮件容量
  megsto:收到邮件的数量。
  bytes_to:同上
  msgsrej:邮件deny的次数。
  msgsdis:邮件discard的次数。
  Mailer :esmtp对外邮件,local本地邮件。
  28              ☆mailq
#/usr/bin/mailq邮件队列查询命令。
  Q-ID 邮件id号。
  Size 邮件容量。
  Q-Time 邮件进入队列(也就是/var/spool/mqueue目录)的时间和不能邮寄的原因。
  Sender/Recipient 发信和收信人的邮箱地址。
  29              ☆sendmail -q
当命令sendmail -q发出以后,sendmail将会试图仍在队列中等待的邮件。
  可以在后面跟上时间‘s’是秒,‘m’分钟(缺省),‘h’小时, ‘d’天,‘w’周.
  30              ☆sendmail管理邮件队列
一般当你发送一封邮件的时候,sendmail倾向于立刻发送这一封电子邮件。但是如果 当前网络忙使得无法立刻投递信件,或者是目标地址的连接速度太慢,无法在短时间内投递到目标地址处,那么sendmail将把待发送的邮件排入队列,并在合适的时候重新发送。
  队列文件通常存放在/var/spool/mqueue下面,每个待发送的邮件由几个文件构成
  例如,我们可以看到下面的目录文件列表:
  [iyunv@mail mqueue]# ls
  dfRAA27175 xfAAA00733 xfBAA00819 xfEAA32763 xfXAA00706
  qfRAA27175 xfAAA00784 xfDAA01360 xfFAA01616
  文件名字总是由一个两字符的前缀加上一个随机数字。前缀有四钟:
  df:邮件内容
  qf:邮件头和一些控制信息
  xf:一些临时文件
  tf:qf文件的临时存储文件
  可以通过看队列中的qf文件来确定当前队列信息,不过通常都可以用mailq程序来完成 对队列状态的查询:
  [iyunv@mail mqueue]# mailq
  Mail Queue (1 request)
  --Q-ID-- --Size-- -----Q-Time----- ------------Sender/Recipient----------- -
  RAA27175 22429 Fri Feb 25 17:34
  : deferred)
  chaszhj@21cn.net
  这表示队列中目前只有一封信,由zhangfl发出,收信人是chaszhj@21cn.net。
  
  
  由sendmail接受到的信件在用户取走之前将暂时存储在/var/spool/mail目录下面,存 储的方法非常简单,就是每个有待读邮件的用户一个文件:
  [iyunv@mail spool]# ls -l /var/spool/mail |more
  total 19364
  -rw-rw---- 1 anyi mail 7559035 Feb 28 22:04 anyi
  -rw-rw---- 1 baixuan mail 514 Nov 7 01:32 baixuan
  -rw-rw---- 1 cwc mail 515 Feb 28 08:35 cwc
  如果一个用户有多封电子邮件,那么这些邮件就被简单地连接在一起构成一个大文件 (所以你会看到非常巨大的邮件文件)。
  如果你面对的是一个很庞大的邮件服务系统,有时会在某个邮件队列中拥塞太多的消 息,你可能想把这个队列暂停并且在网络空闲的时候再发送,暂停一个邮件队列的办法非常简单,就是将/var/spool/mqueue目录移走:
  killall sendmail
  mv /var/spool/mqueue /var/spool/mqueue.stop
  mkdir /var/spool/mqueue
  sendmail -bd
  当网络空闲的时候,可以用-oQ参数立即处理拥塞的队列:
  sendmail -oQ /var/spool/mqueue.stop -q
  31              ☆SMTP协议的基本命令
在/etc/mail/helpfile中有描述
  为了使用这种测试技术,你需要了解SMTP协议的基本命令,这样的命令有14个,在下面列出:
  HELO
  标志发起smtp请求的主机,例如,从client1发起smtp会话,可以使用 HELO client1
  MAIL FROM:
  启动一个邮件会话,在这个行中需要标志发信人的信封地址,例如,要从user1@client1发出邮件,使用MAIL FROM:user1@client1,注意尖括号的用法。
  RCPT TO:
  标志收信人的信封地址,例如,要发送给user2@mail2,使用RCPT TO: user2@mail2。在一个MAIL FROM之后可以给出多个收信人地址,以便实现多副本的传送。
  VRFY
  验证某个地址,例如,要确定test@mail是一个可以投递的地址,使用VRFY test@mail。
  EXPN
  显示某个收件人地址或者用户名的实际名字。例如,要显示postmaster用户的实际投 递地址,使用EXPN postmaster。如果在某个用户的目录下有.forward文件,这个文件的 内容将会被自动使用。
  DATA
  开始写信,在MAIL和RCPT之后可以使用这个命令传输信件正文,传输完毕之后输入一 个.退出。
  QUIT
  关闭smtp会话
  RSET
  复位连接状态
  HELP
  显示这个命令表。
  32              ☆sendmail测试
/etc/mail目录下配置一些文档。
  # cd /etc/mail
  # echo 'examply.com' >> local-host-names 接收邮件的主机名
  # echo 'localhost RELAY' >> access 用来拒绝或允许来自某个域的邮件,本例允许本地转发。
  # makemap hash access < access 生成access.db数据库
  # touch domaintable 用来把旧域名映射互新域名
  # makemap hash domaintable < domaintable
  # touch mailertable 来覆盖向指定域的路由
  # makemap hash mailertable < mailertable
  # touch trusted-users
  # touch virtusertable 用来把用户和域名映射到其它地址
  # makemap hash virtusertable < virtusertable
  # chown root:wheel /var/spool/mqueue/
  # chmod 700 /var/spool/mqueue
  # touch aliases 别名数据库,文本形式。可参照源码目录树下sendmail/aliases文件。
  # newaliases 从文本文件中创建一个新的别名数据库文件。
  # sendmail -v -bi 调试启动。
  /etc/mail/aliases: 42 aliases, longest 10 bytes, 432 bytes total
  如果出现以上提示信息,则启动成功。可用以下命令正式启动:
  
  打开你喜欢的Mail Client,设置smtp服务器为:localhost (假如和服务器在同一台机子上,也可以设置本机的IP),端口为:25.然后随便一段测试信息,填写好接收邮件的地址,按发送。你的Mail Client会提示邮件已发送。实际上你的邮件还在计算机上排队,并未发出!要发送所有排队的邮件,你需要连上网,然后你root身份登陆,并运行:# sendmail -q .现在你的邮件就会发送到指定的邮箱中。
  
  33              ☆postfix安装
在安装Postfix前,需要关闭sendmail服务和开机时的自启动,使用如下命令:
  #service  sendmail  stop
  #chkconfig  sendmail  off
  在http://www.postfix.com/上下载需要的postfix的rpm安装包,或在RHEL5的安装光盘中找到需要安装的rpm包,然后进行安装:
  #rpm  -ivh  postfix-2.3.3-2.i386.rpm (第三张光盘)
  34              ☆postfix收取邮件
为了安全的原因,sendmail和postfix的缺省的配置允许发邮件但是不允许从网络上接收邮件(缺省的它们只接受从回环接口上的连接)。
  修改/etc/postfix/main.cf
  找到并注释如下行
  inet_interfaces = localhost
  取消注释该行:
  inet_interfaces = all
  35              ☆Postfix启动和校验
运行
  #service sendmail start
  #/etc/init.d/postfix start
  使用图形工具
  #system-switch-mail
  使得postfix成为活跃的MTA。
  也可以使用如下的命令行:
  #alternatives -set mta /usr/sbin/sendmail.postfix
  重新启动命令如下:
  #service postfix restart
  确定hostname命令正确的返回您的主机名称。确保DNS配置正确应该是您的FQDN。
  如果sendmail返回您的主机名称为localhost,您可能错误配置了/etc/hosts文件。检查您的/etc/hosts文件,删除所有的但记住留下localhost的指向,然后再试一遍。如果/etc/hosts文件是正确的,那么检查一下在/etc/sysconfig/netwoek中的HOSTNAME的定义。当这些值都正确的时候,启动postfix服务。
  确定postfix在启动的时候没有错误
  Red Hat Linux的安装使用提供的syslog工具来记录所有的信息到文件/var/log/maillog中去。检查此文件中的最后查找任何错误信息。
  试图向root@server1发送简单的邮件并且检查/var/log/maillog的记录文件
  #mail -s `echo $USER` root@panda < /etc/redhat-release
  应该如下所示:
  Jul 26 20:55:10 localhost postfix/pickup[4902]: 717AB335FE: uid=0 from=<root>
  Jul 26 20:55:10 localhost postfix/cleanup[4943]: 717AB335FE: message-id=<20060726125510.717AB335FE@panda.com>
  Jul 26 20:55:10 localhost postfix/qmgr[4903]: 717AB335FE: from=<root@panda.com>, size=314, nrcpt=1 (queue active)
  Jul 26 20:55:10 localhost postfix/local[4945]: 717AB335FE: to=<root@panda.com>, relay=local, delay=0, status=sent (delivered to mailbox)
  Jul 26 20:55:10 localhost postfix/qmgr[4903]: 717AB335FE: removed
  36              ☆Postfix的别名
在postfix决定消息的接受者的目的地的之前,其先试图在别名中查找。
  postfix的主要的别名配置文件是/etc/aliases。为了优化查找,postfix为其别名记录建立了一个哈希表别名数据库/etc/aliases.db(和sendmail类似).该文件通过newaliases命令产生。
  下列命令将增加用户student(如果不存在的话)
  useradd student
  在/etc/aliases 行加入如下的行:
  注意:注释root别名的那一行为postfix
  me: student
  wizards: root, me
  methere: panda@panda.com
  现在运行
  newaliases
  更新数据库
  尝试发送邮件给您定义的收件人:
  echo "hello there" | mail -s "hello" me
  echo "hello there" | mail -s "hello" wizards
  echo "hello there" | mail -s "hello" methere
  是否所有的位于wizards的收件人都受到了邮件?
  要确认/etc/mail/access中打开权限
  37              ☆postfix允许转发
缺省的postfix允许在子网上的任何人通过您的机器进行转发。但是并不是在每一个环境中都安全的。例如,您的机器和其他机器在一起,如果您的本地子网里有一台机器被其他人控制,那么其他的机器都会有麻烦。
  让您的伙伴扮演恶意的垃圾邮件的发送者,该人能够通过telnet到您的机器上的postfix的25号断口,进行垃圾邮件发送地址的欺骗,在panda键入如下命令:
  [iyunv@panda mail]# telnet panda 25
  Trying 127.0.0.1...
  Connected to panda.com (127.0.0.1).
  Escape character is '^]'.
  220 panda.com ESMTP Postfix
  helo root.panda.com
  250 panda.com
  mail from:panda@panda.com
  250 Ok
  rcpt to: root@panda.com
  250 Ok
  data
  354 End data with <CR><LF>.<CR><LF>
  Subject: Faked
  this was faked!
  250 Ok: queued as 9DB2733601
  quit
  221 Bye
  Connection closed by foreign host.
  垃圾邮件现在送到您的机器上了。下一步,看看您的伙伴能不能从您的机器转发给第三台机器:
  由于您的机器已经被配置成为允许混杂转发,垃圾邮件可以通过您的机器进行邮件转发。
  注意/var/log/maillog的变化
  38              ☆postfix不允许转发
编辑文件/etc/postfix/main.cf取消转发。
  查找并且取消注释下面的行,
  mynetworks_style = host
  并且重新启动postfix
  让您的伙伴再从stationY转发垃圾邮件。您的postfix还是一个转发器么?任何一个转发的都会产生如下的消息:
  554 <root@panda.panda.com>: Recipient address rejected: Relay access denied
  39              ☆postfix选择性的转发
对于特定的主机,域或者网络,编辑/etc/postfix/main.cf并且重新启动postfix。对于特定的主机允许通过您的机器进行转发,找到并且取消注释该行:
  mynetworks_style = host
  然后添加新行来允许转发的主机和网络,在这里允许station1和本地转发
  mynetworks = 192.168.152.128, 127.0.0.0/8
  40              ☆postfix接收和转发的条件
(1)默认情况下,postfix接收符合以下条件的邮件:
  目的地为$inet interfaces的邮件;
  目的地为$mydestination的邮件;
  目的地为$virtual_alias_maps的邮件。
  (2)默认情况下,postfix转发符合以下条件的邮件:
  来自客户端IP地址符合$mynetworks的邮件;
  来自客户端主机名称符合relay_domains及其子域的邮件;
  目的地为$relay_domains及其子域的邮件。
  41              ☆主配置文件main.cf
修改/etc/postfix/main.cf的配置:
  myhostname = mail.cngnu.org
  指定运行postfix服务的邮件主机的主机名称(FQDN名)
  mydomain = cngnu.org
  指定运行postfix服务的邮件主机的域名称
  myorigin = $mydomain
  设置由本台邮件主机寄出的每封邮件的邮件头中mail from的地址
  inet interfaces = all
  默认情况下,inet interfaces参数的值被设置为localhost,这表明只能在本地邮件主机上寄信。如果邮件主机上有多个网络接口,而又不想使全部的网络接口都开放Postfix服务,就可以用主机名指定需要开放的网络接口。不过,通常是将所有的网络接口都开放,以便接收从任何网络接口来的邮件,即将inet interfaces参数的值设置为“all”。
  mydestination = $mydomain,$myhostname
  只有当发来的邮件的收件人地址与该参数值相匹配时,Postfix才会将该邮件接收下来。例如,这里将该参数值设置为$mydomain,$myhosname,表明无论来信的收件人地址是xxx@cngnu.org(其中,XXX表示某用户的邮件账户名),还是xxx@mail.cngnu.org,Postfix都会接收这些邮件。
  mynetworks_style = host
  mynetworks = 127.0.0.0/8,192.168.1.0/24
  设置可转发(Relay)哪些网络的邮件.可以使用mynetworks参数来设置。可将该参数值设置为所信任的某台主机的IP地址,也可设置为所信任的某个IP子网或多个IP子网(用“,”或者“”分隔)。这里,将mynetworks参数值设置为192.168.16.0/24,则表示这台邮件主机只转发子网192.168.16.0/24中的客户端所发来的邮件,而拒绝为其他子网转发邮件。
  relay_domains = gdvcp.net
  mynetworks参数是针对邮件来源的IP来设置的,而relay_domains参数则是针对邮件来源的域名或主机名来设置的。例如,将该参数值设置为gdvcp.net,则表示任何由域gdvcp.net发来的邮件都会被认为是信任的,Postfix会自动对这些邮件进行转发。
  virtual_alias_domains = dzxx.cn,panda.com
  用来指定虚拟别名域的名称
  virtual_maps = hash:/etc/postfix/virtual   #,mysql:/etc/postfix/virtual.mysql
  含有虚拟别名域定义的文件路径。
  alias_maps = hash:/etc/aliases
  指定含有用户别名定义的文件路径
  alias_database = hash:/etc/aliases
  指定别名表数据库文件路径。
  home_mailbox = Maildir/
  mailbox_transport = cyrus
  fallback_transport = cyrus
  smtpd_sasl_auth_enable = yes
  指定是否要启用SASL作为SMTP认证方式。默认不启用,这里必须将它启用,所以要将该参数值设置为“yes”。
  smtpd_sasl_local_domain = ''
  如果采用Cyrus-SASL V2版进行认证,那么这里不作设置。
  
  
  smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
  表示通过收件人地址对客户端发来的邮件进行过滤。通常有以下几种限制规则。
  permit_mynetworks:表示只要是收件人地址位于mynetworks参数中指定的网段就可以被转发邮件
  permit_sasl_authenticated:表示允许转发通过SASL认证的邮件。
  reject_unauth_destination:表示拒绝转发含未信任的目标地址的邮件。
  broken_sasl_auth_clients = yes
  表示是否兼容非标准的SMTP认证。有一些Microsoft的SMTP客户端(如Outlook Express 4.x)采用非标准的SMTP认证协议,只需将该参数设置为"yes"就可解决这类不兼容问题。
  smtpd_client_restrictions = permit_sasl_authenticated
  表示限制可以向postfix发起SMTP连接的客户端。如果要禁止未经过认证的客户端向postfix发起SMTP连接,则可将该参数值设置为permit_sasl_authenticated
  smtpd_sasl_security_options = noanonymous
  用来限制某些登录的方式。如果将该参数值设置为noanonymous,则表示禁止采用匿名登录方式。
  permit_mynetworks,
  permit_sasl_authenticated,
  check_recipient_access mysql:/etc/postfix/filter.mysql,
  reject_invalid_hostname,
  reject_non_fqdn_hostname,
  reject_unknown_sender_domain,
  reject_non_fqdn_sender,
  reject_non_fqdn_recipient,
  reject_unknown_recipient_domain,
  reject_unauth_pipelining,
  reject_unauth_destination,
  permit
  如果希望支持更多的虚拟域,可以在mydestination参数后面加上你所要支持的域即可。
  通过virtual和virtual.mysql为系统提供了邮箱本地查询表。
  42              ☆virtual
/etc/postfix/virtual
  虚拟别名 实际名
  @dzxx.cn  @gdvcp.net
  admin@panda.com    lbt
  st123@panda.com      st123001,st123002,st123003
  daliu@panda.com      lbt,liu6812@163.com
  43              ☆master.cf
由postfix运行的守护程序
  44              ☆pcre_table
地址改写的或邮件路由的perl表达式
  45              ☆postfix-files
postfix文件和权限
  46              ☆postfix-script
管理postfix,类似start,stop
  47              ☆regexp_table
从postfix查找账号的表
  用postconf -m来检查
  48              ☆relocated
用户转移到新位置,用这里来重定向
  49              ☆transport
指定一个传输协议
  50              ☆postconf
postconf
  测试配置文件
  postconf -n
  看当前配置文件的路径
  51              ☆重启postfix
修改main.cf和virtual,aliases后
  postmap /etc/postfix/virtual
  生成etc/postfix/virtual.db
  postalias /etc/aliases
  生成/etc/aliases.db
  postfix reload
  重载main.cf
  
  
  
  
  
  52              ☆SMTP认证的配置
如果任何人都可以通过一台邮件服务器来转发邮件,会有什么后果呢?很可能这台邮件服务器就成为了各类广告与垃圾信件的集结地或中转站,网络带宽也会很快被耗尽。为了避免这种情况的出现,MTA默认不会对外开放转发功能,而仅对本机(1ocalhost)开放转发功能。但是,在实际应用中,必须在MTA主配置文件中通过设置mynetworks、relay domains参数来开放一些所信任的网段或网域,否则该邮件服务器几乎没有什么用途。在开放了这些所信任的网段或网域后,还可以通过设置SMTP认证,对要求转发邮件的客户端进行用户身份(用户账户名与密码)验证。只有通过了验证,才能接收该用户寄来的邮件并帮助转发。
  目前,比较常用的SMTP认证机制是通过Cyrus-SASI.。包来实现的。
  53              ☆Cyrus-SASL
是Cyrus Simple Authentication and Security Layer的简写,它最大的功能是为应用程序提供了认证函数库。应用程序可以通过函数库所提供的功能定义认证方式,并让SASL。通过与邮件服务器主机的沟通从而提供认证的功能。
  54              ☆Cyrus-SASL安装
rpm -qa | grep sasl
  55              ☆Cyrus-SASL启动
运行saslauthd守护进程
  service saslauthd restart
  56              ☆Cyrus-SASL认证机制
默认情况下,Cyrus-SASL V2版使用saslauthd这个守护进程进行密码认证,而密码认证的方法有多种,使用下面的命令可查看当前系统中的Cyrus-SASL V2所支持的密码验证机制。
  [iyunv@panda mail]# saslauthd -v
  saslauthd 2.1.19
  authentication mechanisms: getpwent kerberos5 pam rimap shadow ldap
  57              ☆saslauthd配置
配置saslauthd使用shadow认证方案:
  /etc/sysconfig/saslauthd
  MECH=shadow
  配置saslauthd使用PAM认证方案(非默认,需要配置pam,否则测试失败):
  /etc/sysconfig/saslauthd
  MECH=pam
  命令行方式启动验证方案:
  saslauthd -a shadow
  用shadow的用户和密码进行验证
  58              ☆测试Cyrus-SASL
ps aux | grep saslauthd
  service saslauthd restart
  testsaslauthd -u userid -p password
  [iyunv@panda ~]# testsaslauthd -u student -p '111111'
  0: OK "Success."
  如果出现以上信息,就说明saslauthd正常运行了。表示认证功能有效
  服务器启动后,可以用telnet连接服务器。
  # telnet localhost 25
  Trying 127.0.0.1...
  Connected to localhost.
  Escape character is '^]'.
  220 test.tigerhead ESMTP Sendmail 8.12.10/8.12.10; Tue, 30 Mar 2004 14:50:14 +0800
  ehlo test     (!!!!!!!!注意命令是ehlo)你输入的命令,按回车结束。
  250-test.tigerhead Hello LOCALHOST.localdomain [127.0.0.1], pleased to meet you
  250-ENHANCEDSTATUSCODES
  250-PIPELINING
  250-8BITMIME
  250-SIZE
  250-DSN
  250-ETRN
  250-AUTH DIGEST-MD5 CRAM-MD5 LOGIN PLAIN   #就表明SMTP认证成功
  250-DELIVERBY
  250 HELP
  以250-开头的为服务器的响应信息。注意倒数第三行,这就是成功配置smtp验证的显示。
  输入quit离开。
  59              ☆Cyrus-SASL配置MTA
postfix中
  更改main.cf中的配置
  smtpd_sasl_auth_enable = yes
  smtpd_sasl_local_domain =
  smtpd_sasl_security_options = noanonymous
  broken_sasl_auth_clients = yes
  建立/usr/lib/sasl2/smtpd.conf
  设置Postfix使用SASL的saslauthd认证守护进程来支持smtp auth认证,并只打开了plain和login认证模块:
  [iyunv@mail root]# echo pwcheck_method:saslauthd > /usr/lib/sasl2/smtpd.conf
  [iyunv@mail root]# echo mech_list: plain login >> /usr/lib/sasl2/smtpd.conf
  
  
  sendmail中
  更改/etc/mail/sendmail.mc
  去掉下面俩行的注释
  TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
  define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
  如果sendmail没办法收信,就把
  DAEMON_OPTIONS(`Port=587, Name=MSA, M=Ea')dnl 改为
  DAEMON_OPTIONS(`Port=25, Name=MSA')dnl (这一句不能和DAEMON_OPTIONS(`Port=25, Name=MTA')dnl
  同时存在)
  建立/usr/lib/sasl2/Sendmail.conf
  当sendmail要使用SMTP认证时,必须创建一个SASL的配置文件来把MTA程序定义成一个SASL应用。配置文件名为Sendmail.conf(注意是大写的S),位于/usr/lib/sasl2目录中,也就是/usr/local/sasl2/lib/sasl2这个目录,记得上面新建的链接了吗?在该文件中你定义你希望使用的认证数据库方法,以下这个例子使用saslauthd来验证认证请求。
  # echo 'pwcheck_method: saslauthd' > /usr/lib/sasl2/Sendmail.conf(注意大小写)
  如果是pwcheck_method: pam的话是直接调用 pam认证
  如果是pwcheck_method: saslauth的话要启用 saslauth -a pam ,让saslauth调用pam认证
  将这个文件复制成smtpd.conf,即cp Sendmail.conf smtpd.conf,这个文件也要在/usr/lib/sasl2/目录下
  在/etc/pam.d/目录下参照其它文件建立一个“smtp”文件(postfix的是smtp.postfix),内容如下:
  #%PAM-1.0
  auth required pam_stack.so service=system-auth
  account required pam_stack.so service=system-auth
  60              ☆dovecot配置
postfix服务只是一个MTA(邮件传输代理),它只提供SMTP服务,也就是只提供邮件的转发及本地的分发功能。要实现邮件的异地接收,还必须安装POP或IMAP服务。
  dovecot提供了这些服务:POP3,POP3S,IMAP,IMAPS
  编辑/etc/dovecot.conf文件
  在protocols = 一行,加入你需要的的服务
  缺省的ports:
  imap: 143
  imaps: 993
  pop3: 110
  pop3s: 995
  ssl_cert_file 和 ssl_key_file,可以看到dovecot是拿什么文件来做ssl认证的,可以自己创建新的pem文件。
  将disable_plaintext_auth 配置为no(非缺省)
  将auth_mechanisms配置为plain(缺省的)
  将auth_userdb配置为passwd
  也就是说缺省为所有local user 都能登录。
  将auth_passdb设置为shadow
  或者将auth_passdb设置为pam
  增加对pop3配置文件。(缺省没有,要自己建立)
  /etc/pam.d/pop3文件内容如:
  代码:
  auth       required     /lib/security/pam_stack.so service=system-auth
  auth       required     pam_unix.so
  auth       required     pam_listfile.so item=user sense=deny file=/etc/security/dovecot.deny onerr=fail
  account    required     /lib/security/pam_stack.so service=system-auth
  #account           required     pam_access.so
  account    required     pam_unix.so
  用了pam_listfile.so模块,当然也可以用pam_access.so模块来限定。
  61              ☆dovecot.conf
## Dovecot 1.0 configuration file
  # Default values are shown after each value, it's not required to uncomment
  # any of the lines. Exception to this are paths, they're just examples
  # with real defaults being based on configure options. The paths listed here
  # are for configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var
  # --with-ssldir=/usr/share/ssl
  # 运行时存储数据的目录
  #base_dir = /var/run/dovecot/
  # 加入你需要的的服务:
  #  imap imaps pop3 pop3s
  #protocols = imap imaps
  # 监听的IP或者主机地址.
  # It's not currently possible to specify multiple addresses.
  # "*" 是指定监听所有IPv4的interfaces.
  # "[::]" 监听所有IPv6的interfaces,可能会监听所有的IPv4的interfaces但是这个取决于操作系统
  # 指定端口的格式是:"host:port".
  imap_listen = [::]
  pop3_listen = [::]
  # 监听SSL连接的IP或主机地址.
  # Defaults to above non-SSL equilevants if not specified.
  #imaps_listen =
  #pop3s_listen =
  # 禁用SSL/TLS支持.
  #ssl_disable = no
  # PEM encoded X.509 SSL/TLS certificate and private key. They're opened before
  # dropping root privileges, so keep the key file unreadable by anyone but
  # root. Included doc/mkcert.sh can be used to easily generate self-signed
  # certificate, 要保证在dovecot-openssl.cnf中更新域
  #ssl_cert_file = /usr/share/ssl/certs/dovecot.pem
  #ssl_key_file = /usr/share/ssl/private/dovecot.pem
  # SSL parameter file. Master process generates this file for login processes.
  # It contains Diffie Hellman and RSA parameters.
  #ssl_parameters_file = /var/run/dovecot/ssl-parameters.dat
  # How often to regenerate the SSL parameters file. Generation is quite CPU
  # intensive operation. The value is in hours, 0 disables regeneration
  # entirely.
  #ssl_parameters_regenerate = 24
  # Disable LOGIN command and all other plaintext authentications unless
  # SSL/TLS is used (LOGINDISABLED capability). Note that 127.*.*.* and
  # IPv6 ::1 addresses are considered secure, this setting has no effect if
  # you connect from those addresses.
  #disable_plaintext_auth = yes
  # Use this logfile instead of syslog(). /dev/stderr can be used if you want to
  # use stderr for logging (ONLY /dev/stderr - otherwise it is closed).
  #log_path =
  # For informational messages, use this logfile instead of the default
  #info_log_path =
  # Prefix for each line written to log file. % codes are in strftime(3)
  # format.
  #log_timestamp = "%b %d %H:%M:%S "
  ##
  ## Login processes
  ##
  # Directory where authentication process places authentication UNIX sockets
  # which login needs to be able to connect to. The sockets are created when
  # running as root, so you don't have to worry about permissions. Note that
  # everything in this directory is deleted when Dovecot is started.
  login_dir = /var/run/dovecot-login
  # chroot login process to the login_dir. Only reason not to do this is if you
  # wish to run the whole Dovecot without roots.
  #login_chroot = yes
  ##
  ## IMAP login process
  ##
  login = imap
  # Executable location.
  #login_executable = /usr/libexec/dovecot/imap-login
  # User to use for the login process. Create a completely new user for this,
  # and don't use it anywhere else. The user must also belong to a group where
  # only it has access, it's used to control access for authentication process.
  #login_user = dovecot
  # Set max. process size in megabytes. If you don't use
  # login_process_per_connection you might need to grow this.
  #login_process_size = 32
  # Should each login be processed in it's own process (yes), or should one
  # login process be allowed to process multiple connections (no)? Yes is more
  # secure, espcially with SSL/TLS enabled. No is faster since there's no need
  # to create processes all the time.
  #login_process_per_connection = yes
  # Number of login processes to create. If login_process_per_user is
  # yes, this is the number of extra processes waiting for users to log in.
  #login_processes_count = 3
  # Maximum number of extra login processes to create. The extra process count
  # usually stays at login_processes_count, but when multiple users start logging
  # in at the same time more extra processes are created. To prevent fork-bombing
  # we check only once in a second if new processes should be created - if all
  # of them are used at the time, we double their amount until limit set by this
  # setting is reached. This setting is used only if login_process_per_use is yes.
  #login_max_processes_count = 128
  # Maximum number of connections allowed in login state. When this limit is
  # reached, the oldest connections are dropped. If login_process_per_user
  # is no, this is a per-process value, so the absolute maximum number of users
  # logging in actually login_processes_count * max_logging_users.
  #login_max_logging_users = 256
  ##
  ## POP3 login process
  ##
  # Settings default to same as above, so you don't have to set anything
  # unless you want to override them.
  login = pop3
  # Exception to above rule being the executable location.
  #login_executable = /usr/libexec/dovecot/pop3-login
  ##
  ## Mail processes
  ##
  # Maximum number of running mail processes. When this limit is reached,
  # new users aren't allowed to log in.
  #max_mail_processes = 1024
  # Show more verbose process titles (in ps). Currently shows user name and
  # IP address. Useful for seeing who are actually using the IMAP processes
  # (eg. shared mailboxes or if same uid is used for multiple accounts).
  #verbose_proctitle = no
  # Show protocol level SSL errors.
  #verbose_ssl = no
  # Valid UID range for users, defaults to 500 and above. This is mostly
  # to make sure that users can't log in as daemons or other system users.
  # Note that denying root logins is hardcoded to dovecot binary and can't
  # be done even if first_valid_uid is set to 0.
  #first_valid_uid = 500
  #last_valid_uid = 0
  # Valid GID range for users, defaults to non-root/wheel. Users having
  # non-valid GID as primary group ID aren't allowed to log in. If user
  # belongs to supplementary groups with non-valid GIDs, those groups are
  # not set.
  #first_valid_gid = 1
  #last_valid_gid = 0
  # Grant access to these extra groups for mail processes. Typical use would be
  # to give "mail" group write access to /var/mail to be able to create dotlocks.
  #mail_extra_groups =
  # ':' separated list of directories under which chrooting is allowed for mail
  # processes (ie. /var/mail will allow chrooting to /var/mail/foo/bar too).
  # This setting doesn't affect login_chroot or auth_chroot variables.
  # WARNING: Never add directories here which local users can modify, that
  # may lead to root exploit. Usually this should be done only if you don't
  # allow shell access for users. See doc/configuration.txt for more information.
  #valid_chroot_dirs =
  # Default chroot directory for mail processes. This can be overridden by
  # giving /./ in user's home directory (eg. /home/./user chroots into /home).
  #mail_chroot =
  # Default MAIL environment to use when it's not set. By leaving this empty
  # dovecot tries to do some automatic detection as described in
  # doc/mail-storages.txt. There's a few special variables you can use:
  #   %u - username
  #   %n - user part in user@domain, same as %u if there's no domain
  #   %d - domain part in user@domain, empty if user there's no domain
  #   %h - home directory
  # You can also limit a width of string by giving the number of max. characters
  # after the '%' character. For example %1u gives the first character of
  # username. Some examples:
  #   default_mail_env = maildir:/var/mail/%1u/%u/Maildir
  #   default_mail_env = mbox:~/mail/:INBOX=/var/mail/%u
  #   default_mail_env = mbox:/var/mail/%d/%n/:INDEX=/var/indexes/%d/%n
  #default_mail_env =
  # Space-separated list of fields to cache for all mails. Currently these
  # fields are allowed followed by a list of commands they speed up:
  ##  Envelope      - FETCH ENVELOPE and SEARCH FROM, TO, CC, BCC, SUBJECT,
  #                  SENTBEFORE, SENTON, SENTSINCE, HEADER MESSAGE-ID,
  #                  HEADER IN-REPLY-TO
  #  Body          - FETCH BODY
  #  Bodystructure - FETCH BODY, BODYSTRUCTURE
  #  MessagePart   - FETCH BODY[1.2.3] (ie. body parts), RFC822.SIZE,
  #                  SEARCH SMALLER, LARGER, also speeds up BODY/BODYSTRUCTURE
  #                  generation. This is always set with mbox mailboxes, and
  #                  also default with Maildir.
  # Different IMAP clients work in different ways, that's why Dovecot by default
  # only caches MessagePart which speeds up most operations. Whenever client
  # does something where caching could be used, the field is automatically marked
  # to be cached later. For example after FETCH BODY the BODY will be cached
  # for all new messages. Normally you should leave this alone, unless you know
  # what most of your IMAP clients are. Caching more fields than needed makes
  # the index files larger and generate useless I/O.
  # With maildir there's one extra optimization - if nothing is cached, indexing
  # the maildir becomes much faster since it's not opening any of the mail files.
  # This could be useful if your IMAP clients access only new mails.
  #mail_cache_fields = MessagePart
  # Space-separated list of fields that Dovecot should never set to be cached.
  # Useful if you want to save disk space at the cost of more I/O when the fields
  # needed.
  #mail_never_cache_fields =
  # Workarounds for various client bugs:
  #   oe6-fetch-no-newmail:
  #     Never send EXISTS/RECENT when replying to FETCH command. Outlook Express
  #     seems to think they are FETCH replies and gives user "Message no longer
  #     in server" error. Note that OE6 still breaks even with this workaround
  #     if synchronization is set to "Headers Only".
  #   outlook-idle:
  #     Outlook and Outlook Express never abort IDLE command, so if no mail
  #     arrives in half a hour, Dovecot closes the connection. This is still
  #     fine, except Outlook doesn't connect back so you don't see if new mail
  #     arrives.
  #   outlook-pop3-no-nuls:
  #     Outlook and Outlook Express hang if mails contain NUL characters.
  #     This setting replaces them with 0x80 character.
  #client_workarounds =
  
  # Dovecot can notify client of new mail in selected mailbox soon after it's
  # received. This setting specifies the minimum interval in seconds between
  # new mail notifications to client - internally they may be checked more or
  # less often. Setting this to 0 disables the checking.
  # NOTE: Evolution client breaks with this option when it's trying to APPEND.
  #mailbox_check_interval = 0
  
  # Like mailbox_check_interval, but used for IDLE command.
  #mailbox_idle_check_interval = 30
  
  # Allow full filesystem access to clients. There's no access checks other than
  # what the operating system does for the active UID/GID. It works with both
  # maildir and mboxes, allowing you to prefix mailboxes names with eg. /path/
  # or ~user/.
  #mail_full_filesystem_access = no
  
  # Maximum allowed length for custom flag name. It's only forced when trying
  # to create new flags.
  #mail_max_flag_length = 50
  
  # Save mails with CR+LF instead of plain LF. This makes sending those mails
  # take less CPU, especially with sendfile() syscall with Linux and FreeBSD.
  # But it also creates a bit more disk I/O which may just make it slower.
  #mail_save_crlf = no
  
  # Use mmap() instead of read() to read mail files. read() seems to be a bit
  # faster with my Linux/x86 and it's better with NFS, so that's the default.
  #mail_read_mmaped = no
  
  # By default LIST command returns all entries in maildir beginning with dot.
  # Enabling this option makes Dovecot return only entries which are directories.
  # This is done by stat()ing each entry, so it causes more disk I/O.
  # (For systems setting struct dirent->d_type, this check is free and it's
  # done always regardless of this setting)
  #maildir_stat_dirs = no
  
  # Copy mail to another folders using hard links. This is much faster than
  # actually copying the file. This is problematic only if something modifies
  # the mail in one folder but doesn't want it modified in the others. I don't
  # know any MUA which would modify mail files directly. IMAP protocol also
  # requires that the mails don't change, so it would be problematic in any case.
  # If you care about performance, enable it.
  #maildir_copy_with_hardlinks = no
  
  # Check if mails' content has been changed by external programs. This slows
  # down things as extra stat() needs to be called for each file. If changes are
  # noticed, the message is treated as a new message, since IMAP protocol
  # specifies that existing messages are immutable.
  #maildir_check_content_changes = no
  # Which locking methods to use for locking mbox. There's three available:
  #  dotlock: Create <mailbox>.lock file. This is the oldest and most NFS-safe
  #           solution. If you want to use /var/mail/ like directory, the users
  #           will need write access to that directory.
  #  fcntl  : Use this if possible. Works with NFS too if lockd is used.
  #  flock  : May not exist in all systems. Doesn't work with NFS.
  # You can use both fcntl and flock too; if you do the order they're declared
  # with is important to avoid deadlocks if other MTAs/MUAs are using both fcntl
  # and flock. Some operating systems don't allow using both of them
  # simultaneously, eg. BSDs. If dotlock is used, it's always created first.
  mbox_locks = fcntl
  # Should we create dotlock file even when we want only a read-lock? Setting
  # this to yes hurts the performance when the mailbox is accessed simultaneously
  # by multiple processes, but it's needed for reliable reading if no other
  # locking methods are available.
  #mbox_read_dotlock = no
  # Maximum time in seconds to wait for lock (all of them) before aborting.
  #mbox_lock_timeout = 300
  # If dotlock exists but the mailbox isn't modified in any way, override the
  # lock file after this many seconds.
  #mbox_dotlock_change_timeout = 30
  # umask to use for mail files and directories
  #umask = 0077
  # Drop all privileges before exec()ing the mail process. This is mostly
  # meant for debugging, otherwise you don't get core dumps. Note that setting
  # this to yes means that log file is opened as the logged in user, which
  # might not work. It could also be a small security risk if you use single UID
  # for multiple users, as the users could ptrace() each others processes then.
  #mail_drop_priv_before_exec = no
  ##
  ## IMAP process
  ##
  # Executable location
  #imap_executable = /usr/libexec/dovecot/imap
  # Set max. process size in megabytes. Most of the memory goes to mmap()ing
  # files, so it shouldn't harm much even if this limit is set pretty high.
  #imap_process_size = 256
  # Support for dynamically loadable modules.
  #imap_use_modules = no
  #imap_modules = /usr/lib/dovecot/imap
  ##
  ## POP3 process
  ##
  # Executable location
  #pop3_executable = /usr/libexec/dovecot/pop3
  # Set max. process size in megabytes. Most of the memory goes to mmap()ing
  # files, so it shouldn't harm much even if this limit is set pretty high.
  #pop3_process_size = 256
  # Support for dynamically loadable modules.
  #pop3_use_modules = no
  #pop3_modules = /usr/lib/dovecot/pop3
  ##
  ## Authentication processes
  ##
  # An Authentication process is a child process used by Dovecot that
  # handles the authentication steps. The steps cover an authentication
  # mechanism (auth_mechanisms, how the client authenticates in the IMAP or
  # POP3 protocol), which password database should be queried (auth_passdb),
  # and which user database should be queried (auth_userdb, to obtain
  # UID, GID, and location of the user's mailbox/home directory).
  # You can have multiple processes, though a typical configuration will
  # have only one. Each time "auth = xx" is seen, a new process
  # definition is started. The point of multiple processes is to be able
  # to set stricter permissions. (See auth_user below.)
  # Just remember that only one Authentication process is asked for the
  # password, so you can't have different passwords accessible through
  # different process definitions (unless they have different
  # auth_mechanisms, and you're ok with having different password for
  # each mechanisms).
  # Authentication process name.
  auth = default
  # Specifies how the client authenticates in the IMAP protocol.
  # Space separated list of permitted authentication mechanisms:
  #   anonymous plain digest-md5 cram-md5
  # anonymous - No authentication required.
  # plain - The password is sent as plain text. All IMAP/POP3 clients
  #  support this, and the password can be encrypted by Dovecot to match
  #  any of the encryption schemes used in password databases.
  # digest-md5 and cram-md5 - both encrypt the password so it is more
  #  secure in transit, but are not well supported by clients, and
  #  require that the password database use a matching encryption
  #  scheme (or be in plaintext).
  # See auth.txt for more details.
  # If you are using SSL there is less benefit to digest-md5 and
  # cram-md5 as the communication is already encrypted.
  auth_mechanisms = plain
  # Space separated list of realms for SASL authentication mechanisms that need
  # them. You can leave it empty if you don't want to support multiple realms.
  # Many clients simply use the first one listed here, so keep the default realm
  # first.
  #auth_realms =
  # Default realm/domain to use if none was specified. This is used for both
  # SASL realms and appending @domain to username in plaintext logins.
  #auth_default_realm =
  # Where user database is kept:
  #   passwd: /etc/passwd or similiar, using getpwnam()
  #   passwd-file <path>: passwd-like file with specified location
  #   static uid=<uid> gid=<gid> home=<dir template>: static settings
  #   vpopmail: vpopmail library
  #   ldap <config path>: LDAP, see doc/dovecot-ldap.conf
  #   pgsql <config path>: a PostgreSQL database, see doc/dovecot-pgsql.conf
  auth_userdb = passwd
  # Where password database is kept:
  #   passwd: /etc/passwd or similiar, using getpwnam()
  #   shadow: /etc/shadow or similiar, using getspnam()
  #   pam [<service> | *]: PAM authentication
  #   passwd-file <path>: passwd-like file with specified location
  #   vpopmail: vpopmail authentication
  #   ldap <config path>: LDAP, see doc/dovecot-ldap.conf
  #   pgsql <config path>: a PostgreSQL database, see doc/dovecot-pgsql.conf
  #auth_passdb = pgsql /usr/local/etc/dovecot-pgsql.conf
  auth_passdb = pam
  #auth_executable = /usr/libexec/dovecot/dovecot-auth
  # Set max. process size in megabytes.
  #auth_process_size = 256
  # User to use for the process. This user needs access to only user and
  # password databases, nothing else. Only shadow and pam authentication
  # requires roots, so use something else if possible. Note that passwd
  # authentication with BSDs internally accesses shadow files, which also
  # requires roots.
  auth_user = root
  # Directory where to chroot the process. Most authentication backends don't
  # work if this is set, and there's no point chrooting if auth_user is root.
  #auth_chroot =
  # Number of authentication processes to create
  #auth_count = 1
  # List of allowed characters in username. If the user-given username contains
  # a character not listed in here, the login automatically fails. This is just
  # an extra check to make sure user can't exploit any potential quote escaping
  # vulnerabilities with SQL/LDAP databases. If you want to allow all characters,
  # set this value to empty.
  #auth_username_chars = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@
  # Username to use for users logging in with ANONYMOUS SASL mechanism
  #auth_anonymous_username = anonymous
  # More verbose logging. Useful for figuring out why authentication isn't
  # working.
  #auth_verbose = no
  # Even more verbose logging for debugging purposes. Shows for example SQL
  # queries.
  #auth_debug = no
  # digest-md5 authentication process. It requires special MD5 passwords which
  # /etc/shadow and PAM doesn't support, so we never need roots to handle it.
  # Note that the passwd-file is opened before chrooting and dropping root
  # privileges, so it may be 0600-root owned file.
  #auth = digest_md5
  #auth_mechanisms = digest-md5
  #auth_realms =
  #auth_userdb = passwd-file /etc/passwd.imap
  #auth_passdb = passwd-file /etc/passwd.imap
  #auth_user = imapauth
  #auth_chroot =
  # if you plan to use only passwd-file, you don't need the two auth processes,
  # simply set "auth_methods = plain digest-md5"
  62              ☆Mail测试
[iyunv@mail root]# mail virtualuser@cngnu.org
  Subject: test by me
  this is a test.
  CC:
  [iyunv@mail root]# mailq
  Mail queue is empty
  [iyunv@mail root]# tail /var/log/maillog
  使用mailq来查看邮件队列是否有错误,并查看/var/log/mail/*是否有错误信息。如果一切正常,说明信件已经发送到tester了。
  63              ☆测试pop/imap

  测试收信,先测试POP3:
  telnet panda 110
  然后输入:
  user username
  +OK
  pass password   (注意是pass)
  如果LOGIN成功,会有提示。
  +OK Logged in.
  list
  +OK 2 messages:
  1 849
  2 823
  这样的返回信息说明已经一切正常,可以提供服务了。
  STAT
  +OK 2 1672
  TOP 1
  +OK
  Return-Path: <student@panda.panda.com>
  Received: from panda ([192.168.152.1])
  by panda.panda.com (8.13.1/8.13.1) with SMTP id k7KJE2DZ004002
  for <student@panda.panda.com>; Mon, 21 Aug 2006 03:14:02 +0800
  Date: Mon, 21 Aug 2006 03:14:02 +0800
  From: student@panda.panda.com
  Message-Id: <200608201914.k7KJE2DZ004002@panda.panda.com>
  To: <student@panda.panda.com>
  Subject: =?utf-8?B?TWljcm9zb2Z0IE9mZmljZSBPdXRsb29rIOa1i+ivlea2iOaBrw==?=
  MIME-Version: 1.0
  Content-Type: text/plain;
  charset="utf-8"
  Content-Transfer-Encoding: 8bit
  X-IMAPbase: 1154223507 6
  Status: O
  X-UID: 5
  Content-Length: 120
  X-Keywords:         
  DELE 1
  +OK Marked to be deleted.
  QUIT
  +OK Sayonara
  Connection closed by foreign host.
  再测试IMAP:
  imtest -m login -a panda@panda.panda.com localhost
  C: C01 CAPABILITY
  S: * OK mail.cngnu.org Cyrus IMAP4 v2.1.16 server ready
  S: * CAPABILITY IMAP4 IMAP4rev1 ACL QUOTA LITERAL+ NAMESPACE UIDPLUS ID NO_ATOMIC_RENAME UNSELECT MULTIAPPEND SORT THREAD=ORDEREDSUBJECT THREAD=REFERENCES IDLE
  S: C01 OK Completed
  Password:
  C: L01 LOGIN virtualuser {6}
  + go ahead
  C: <omitted>
  L01 OK User logged in
  Authenticated.
  Security strength factor: 0
  . select inbox
  * FLAGS (/Answered /Flagged /Draft /Deleted /Seen)
  * OK [PERMANENTFLAGS (/Answered /Flagged /Draft /Deleted /Seen /*)]
  * 1 EXISTS
  * 1 RECENT
  * OK [UIDVALIDITY 1021736432]
  * OK [UIDNEXT 3]
  . OK [READ-WRITE] Completed
  . fetch 1:1 (FLAGS BODY[HEADER.FIELDS (DATE FROM)])
  * 1 FETCH (FLAGS (/Seen) BODY[HEADER.FIELDS (DATE FROM)] {68}
  Date: Mon, 20 May 2002 09:26:09 +0800 (CST)
  From: wxy@cngnu.org
  )
  . OK Completed
  . logout
  * BYE LOGOUT received
  . OK Completed
  64              ☆procmail
邮件分拣
  Linux的sendmail使用procmail作为信件的最终投递代理。这个程序有一些非常有用的 ,对于我们来说,最重要的功能是信件的自动过滤和分拣功能。
  信件分拣大概是用户最希望的功能,它按照邮件的文件头(发信地址,收信地址等等 )甚至邮件的正文进行归类,并且可以自动存放在各个文件中或者转发给别的用户账号 。马上我们会看到,用procmail配置自动分拣是一件非常容易的事情。
  通常的sendmail配置中已经使用了procmail作为邮件最终投递代理,如果你的sendmail已经改乱了,可以使用FEATURE(local_procmail)设置这个功能。
  procmail主要依靠用户宿主目录下面的.procmailrc中的信息来处理邮件.如果这个配 制文件不存在,则procmail只是简单的将邮件保存到用户的信箱中.
  
  一般来说,.procmailrc文件由配置行和行为规则组成,规则的一般格式是
  0 选项
  [零个或多个条件,每个一行]
  [动作命令] [动作命令]
  0表示开始一条规则,后面可以加上一些单字符的选项,选项主要有下面的一些:
  H 搜索匹配邮件头部
  B 搜索匹配整个邮件
  D 匹配时区分大小写
  A 如果前面最近的一个没有A或a选项的规则执行,执行本规则
  a 如果上面一条规则执行,则本规则执行
  E 同A相反,前面最近的没有E或e选项的规则没有执行,则执行本规则
  e 同a相反
  h 通过管道传送邮件首部(缺省)
  b 通过管道传送邮件主体(缺省)
  c 复制一个邮件
  I 忽略所有写操作中的错误
  r 原始模式,即procmail不对mail进行任何模式的处理
  条件用一个*号开始,后面跟上正则表达式
  动作命令就是procmail在规则成功之后使用的命令,一般的命令有下面一些:
  {}
  开始一个语句段,表示把一组命令集合成一个动作。如果你要嵌套处理规则,(例如 ,对于来自test的邮件,区分是含有computer字符串还是含有physics字符串)那么必须 使用语句段把子规则括起来。
  !
  转发信件给某个用户
  |
  启用管道将邮件传送给后面的程序,例如|auto-reply表示启动auto-reply程序并且将 邮件内容作为标准输入传递给它。
  任意文件名
  将邮件存入某个文件。如果文件已经存在,就添加在文件的末尾。
  对于熟悉perl或C语言的的用户,很容易用procmail的管道功能做出邮件的自动回复程序,这里不再介绍了,想进一步了解procmail的用户可以用
  65              ☆使用POP客户端
所有的现在的邮件用户代理(MUA),例如netscape,elm,Outlook,pine和mutt都是使用POP的,可以被用作POP的客户端。每一个的配置都有所不同。同样有一个流行字符界面的的POP客户端叫做fetchmail。fetchmail是高度的可配置的,可以查询多个邮箱,可以作为守护进程运行,这样使得其每五分钟查询用户的邮箱。fetchmail在主机上递送邮件到邮件传送代理(MTA),例如sendmail。我们将勾画出以后如何安装fetchmail和使用其来查询我们装过的POP服务器。
  注意到有很多选项可以影响fetchmail的行为。建立一个~/.fetchmailrc文件如下所示:
  ~student/.fetchmailrc
  poll stationX.exmaple.com with protocol pop3: user studentXX there is user studentXX here password "password"
  由于密码存储在该文件中,因此fetchmail将会拒绝运行除非您把该文件的属性设定为对于仅仅文件的所有者只读。注意还可以使用chown改变由root创建的文件的所有者为studentXX。
  chmod 600 ~student/.fetchmailrc
  chown student.student ~student/.fetchmailrc
  尝试使用studentXX登陆到POP3邮箱
  echo "hello student" | mail -s "Hola" student
  su - student
  fetchmail -v
  exit
  fetchmail能不能接收到student的POP邮件?将递送student的邮件到哪里?比从本地获取POP邮件有意义么?
  让您的伙伴在另外一台机器上建立相同的~/.fetchmailrc文件(或者配置其它诸如mozilla的MTA)试图从您的服务器上进行收信。
  66              ☆fetchmail
许多用户有多个邮件账户,有些在你的管理范围之内,有些在别的服务器上面。管理 所有这些邮件是非常恶心的事情。另外,也许你的系统仅仅是一个拨号代理(参考第八 章),不可能始终接在internet上面。你需要的是在系统连接到internet的时候发出电 子邮件,同时自动去接收电子邮件。在国内,典型的做法是每人申请一个本地电子邮件 账户和一个免费电子邮件账号,问题就是,如何从另外的ISP提供的电子邮件账号哪里自 动地接收邮件?
  当然你可以让你的用户自己解决这个问题,不过这种僵硬的方法不见得合适。一般我 们采用另外的办法,就是fetchmail,它是一个自动的邮件接力程序,可以让它从远程的 pop3账号处取得邮件,然后扔进用户的本地邮箱。(关于pop3的情况参考下一节)
  可以直接用命令行调用fetchmail:
  $ fetchmail -p [协议] -u [用户名] [服务器]
  fetchmail得到的信息将直接投入localhost机器,账号是你启动fetchmail时使用的账 号。
  $ fetchmail -p POP3 -u yuanban mail.asnc.edu.cn
  Enter password for yuanban@mail.asnc.edu.cn:
  使用pop3协议从mail.asnc.edu.cn取得yuanban的信件。fetchmail要求你输入yuanba n的密码,然后进行验证,成功的话会出现下面的信息:
  1 message for yuanban at mail.asnc.edu.cn (551840 octets).
  reading message 1 of 1 (551840 octets) ................................... .....d
  表示已经完成了一封信件的转交。
  
  
  
  
  
  对于更复杂的情况,建议你使用fetchmail的配置文件,即用户宿主目录下面的.fetc hmailrc。这个文件的详细资料可以参考fetchmail的文档,这里只用一个简单地例子来 介绍它。我们看一个简单的.fetchmailrc范例:
  set syslog
  set postmaster "isee"
  poll 202.96.44.11 with proto POP3 and options
  envelope Delivered-To:
  user "mere" there with password "xxxxxxx" is isee@snail.home here
  no keep
  user "isee" there with password "yyyyyyy" is isee@snail.home here
  no keep
  这个范例相当简单。fetchmail在读取配置文件的时候会忽略所有的"there","here", "and","with","has","wants","options"之类的单词。
  第一行set syslog程序定义fetchmail的记录文件使用系统记录功能。set postmaste r设置的是出错时的管理员账号,接下来的poll行定义了fetchmail使用的协议为POP3, 连接的服务器是202.96.44.11。
  envelope Delivered-To:这个选项比较有趣,它在信封上加上一个Delivered-To说明 ,这主要是为了让fetchmail可以把信件投递到一些使用qmail(见下面)的系统中。
  接下来是fetchmail的主体部分,一个user的行定义了一个接力方法,现在的定义是取 得202.96.44.11服务器上mere账号的信件,取信的口令是xxxxxxx,然后投递到isee@sn ail.home,同样,isee的信件也被自动投递到isee@snail.home。no-keep选项表示不在 原始服务器上保留邮件。
  下面是配置fetchmail的一些常用选项:
  set logfile 制定log文件
  set syslog 使用系统log文件
  via 指定DNS机器名来取代poll中的机器明
  proto 指定协议
  port 指定端口
  timeout 指定超时时间
  interface 指定网络界面
  user 指定远程用户
  is 将本地用户和远程用户联系起来
  to 同is
  pass 口令
  preconnect 连接开始前执行的外部命令
  postconnect 连接结束后执行的外部命令
  keep 在服务器上保留邮件备份
  no keep 不保留邮件备份
  在配置了.fetchmailrc之后,只要直接执行fetchmail就可以实现自动的信件投递了。 实际上,你甚至可能使用fetchmail作为一个daemon程序来实现自动的邮件转交,或是设 置fetchmail让它支持qmail的虚拟域。
  在fetchmail的发行版本中还提供了一个图形化的fetchmail配置程序,称为fetchmail conf。如果你对fetchmail的语法感到困难,只要使用这个程序就可以进行配置。启动这 个程序的方法很简单,直接在xterm下面执行fetchmailconf &:
  图7.1 配置fetchmail
  选择configure fetchmail出现:
  图7.2 配置fetchmail(2)
  只要选择Novice Configuration,然后出现服务器设置选单:
  图7.3 配置fetchmail(3)
  在New Server中加入你准备收信的服务器,然后回车,服务器名字就会出现在列表框 中,双击服务器名字,编辑关于服务器的设置:
  图7.4 配置fetchmail(4)
  设置服务器的类型和服务器上的账户名字,双击账户名字并且输入对应的密码以及和 本地账户之间的对应关系,OK退出就可以了
  67              ☆squirrelmail
rpm -q squirrelmail
  squirrelmail的主配置文件为/etc/squirrelmail/config.php
  更改这个配置用/usr/share/squirrelmail/config/conf.pl
  更方便
  
  本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/tjj101218/archive/2009/01/02/3683467.aspx

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-143512-1-1.html 上篇帖子: 配置简单带认证的Sendmail服务器 ( 下篇帖子: ubuntu下wordpress安装Sendmail发送邮件
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表