wheat 发表于 2018-5-11 10:54:43

Linux网络服务_邮件服务器

  
Linux网络服务_邮件服务器-Redhat Enterprise 5.9
  

  案例环境:
  邮件服务器:mail.tarena.com192.168.1.100
  邮件域:@tarena.com
  邮件账号:服务器的系统用户
  发信服务软件:postfix
  授信服务软件:dovecot
  

第一部分:安装并测试发信服务软件postfix
  第一步:与邮件相关的DNS设置:
  需要事先配置dns,在正向文件中添加相应的MX记录、A记录
  # cat /var/named/chroot/var/named/tarena.com.zheng
  $TTL    86400
  @       IN      SOA    tarena.com. root.tarena.com.(
                                      2014031001 ; Serial
                                      28800      ; Refresh
                                      14400      ; Retry
                                      3600000    ; Expire
                                      86400)   ; Minimum
        IN      NS       server1.tarena.com.
         IN   MX5   mail.tarena.com.
  server1 IN      A      192.168.1.100
  mail    IN    A       192.168.1.100
  #
  

  第二步:安装postfix服务
  注:
  1,在安装postfix服务之前,需要先关闭sendmail服务,避免端口冲突
  2,依赖包为perl-DBI,安装完后要添加postfix服务
  3,需要手动添加postfix服务:chkconfig --add postfix
  

  # service sendmail stop
  关闭 sm-client:                                           [确定]
  关闭 sendmail:                                          [确定]
  # chkconfig sendmail off
  # yum -y install postfix
  # chkconfig --add postfix
  # chkconfig --list postfix
  postfix         0:关闭1:关闭2:启用3:启用4:启用5:启用6:关闭
  # service postfix start
  启动 postfix:                                             [确定]
  #
  

  第三步:修改主配置文件:/etc/postfix/main.cf
  注:
  服务配置:/etc/postfix/main.cf
  主程序配置:/etc/postfix/master.cf
  postconf辅助工具:
  无选项时,查看当前的有效配置
  选项-n,查看非默认配置
  选项-d,查看默认的配置
  利用postconf提取有效配置,排除干扰项、只保留非默认的配置
  注:由于postconf-n在输出信息的过程中,需要读取main.cf文件,所以,先执行
  post -n >test.txt,之后再将main.cf更名为main.cf.old,否则,非默认的配置内容将会改变,最后再在将text.txt改名为main.cf,那么main.cf里面的内容就为非默认的配置了。
  # cd /etc/postfix/
  # postconf -n > test.txt
  # mv main.cf main.cf.old
  # mv test.txt main.cf
  # vim main.cf
  # cat main.cf
  alias_database = hash:/etc/aliases
  alias_maps = hash:/etc/aliases
  command_directory = /usr/sbin
  config_directory = /etc/postfix
  daemon_directory = /usr/libexec/postfix
  debug_peer_level = 2
  html_directory = no
  #inet_interfaces = localhost       //把这一行注释掉,否则只允许本地回环地址
  mail_owner = postfix
  mailq_path = /usr/bin/mailq.postfix
  manpage_directory = /usr/share/man
  mydestination = $myhostname, localhost.$mydomain,localhost
  newaliases_path = /usr/bin/newaliases.postfix
  queue_directory = /var/spool/postfix
  readme_directory =/usr/share/doc/postfix-2.3.3/README_FILES
  sample_directory =/usr/share/doc/postfix-2.3.3/samples
  sendmail_path = /usr/sbin/sendmail.postfix
  setgid_group = postdrop
  unknown_local_recipient_reject_code = 550
  myhostname = mail.tarena.com       //邮件服务器名子
  mydomain = tarena.com       //邮件域
  myorigin = $mydomain   //显示发件域,随邮件域变化
  mydestination = $mydomain,$myhostname   //本地投递域
  home_mailbox = Maildir/         //邮箱类型,这里指定在家目录的Maildir下
  # service postfix restart
  关闭 postfix:                                             [确定]
  启动 postfix:                                             [确定]
  # netstat -anpt | grep 25
  tcp      0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      11475/master
  #
  

  第四步:测试SMTP发信
  使用telnet工具:连接到25端口,执行发信指令
  基本的SMTP指令
      HELO:宣告客户机地址(大小写均可)
      MAIL FROM:指定发件人邮箱地址
      RCPT TO:指定收件人邮箱地址
      DATA:编写邮件内容,SUBJECT为主题,结束则需另起一行,一点“.”结束
  #telnet mail.tarena.com 25
  Trying192.168.1.100...
  Connected tomail.tarena.com (192.168.1.100).
  Escape character is'^]'.
  220 mail.tarena.comESMTP Postfix
  helo mail.tarena.com            //给mail.tarena.com打招呼
  250 mail.tarena.com             //mail.tarena.com给出250回应,如果是501则失败
  mail from:nick@tarena.com       //发信人为nick
  250 2.1.0 Ok
  rcpt to:hunter@tarena.com       //收信任为hunter
  250 2.1.5 Ok
  data      //正文的开始
  354 End data with<CR><LF>.<CR><LF>   //提示以“.”结束
  subject:Test mail         //邮件标题,subject开头
  this is a test mail...         //这是邮件内容
  .         //以“.”结束
  250 2.0.0 Ok: queuedas A68ED41BFB3
  quit      //quit退出邮件系统
  221 2.0.0 Bye
  Connection closed byforeign host.
  # ls /home/hunter/Maildir/new/      //查看新邮件列表
  1394448613.V803I30cf17M502725.server1.tarena.com
  # cd /home/hunter/Maildir/new/      //邮件存放位置
  # cat 1394448613.V803I30cf17M502725.server1.tarena.com
  Return-Path:<nick@tarena.com>
  X-Original-To:hunter@tarena.com
  Delivered-To:hunter@tarena.com
  Received:from mail.tarena.com (server1.tarena.com )
        by mail.tarena.com (Postfix) with SMTPid A68ED41BFB3
        for <hunter@tarena.com>; Mon, 10Mar 2014 18:49:16 +0800 (CST)
  subject:Testmail
  Message-Id:<20140310104939.A68ED41BFB3@mail.tarena.com>
  Date:Mon, 10 Mar 2014 18:49:16 +0800 (CST)
  From:nick@tarena.com
  To:undisclosed-recipients:;
  

  thisis a test mail ...
  #
  

第二部分:安装并测试收信服务软件dovecot
  

  第一步:安装dovecot软件并启动该服务
  #yum install dovecot
  #chkconfig --list dovecot
  dovecot         0:关闭1:关闭2:关闭3:关闭4:关闭5:关闭6:关闭
  #service dovecot start
  启动 DovecotImap:                                        [确定]
  #chkconfig dovecot on
  #
  

  第二步:配置收信服务
  调整dovecot配置:
  1,整个配置文件基本不需更改,只需保证以下三个字段正确即可:
  /etc/dovecot.conf配置文件中
  ssl_disable = yes                   //禁用ssl加密
  disable_plaintest_auth= no         //允许明文认证通信
  mail_location =maildir:~/Maildir   //设置邮箱路径
  2,重新启动服务:service dovecot restart
  3,保证tcp的110和143端口开启
  # netstat -anpt | grep dovecot
  tcp      0      0 :::993         :::*            LISTEN      12138/dovecot      
  tcp      0      0 :::995         :::*            LISTEN      12138/dovecot      
  tcp      0      0 :::110         :::*            LISTEN   12138/dovecot      
  tcp      0      0 :::143         :::*            LISTEN   12138/dovecot      
  #
  

  

  第三步:测试POP3/IMAP收信
  使用telnet工具:连接到110或143端口,执行收信指令
  基本的SMTP指令:
      USER:指定登录账号
      PASS:指定用于验证的密码
      LIST:查看邮件列表
      RETR:获取指定编号的邮件内容
  

  # telnet mail.tarena.com 110
  Trying192.168.1.100...
  Connected tomail.tarena.com (192.168.1.100).
  Escape character is'^]'.
  +OK Dovecot ready.
  user hunter
  +OK
  pass 123
  +OK Logged in.
  list
  +OK 2 messages:
  1 473
  .
  retr 1
  +OK 491 octets
  Return-Path:<nick@tarena.com>
  X-Original-To:hunter@tarena.com
  Delivered-To:hunter@tarena.com
  Received: frommail.tarena.com (server1.tarena.com )
        by mail.tarena.com (Postfix) with SMTPid A68ED41BFB3
        for <hunter@tarena.com>; Mon, 10Mar 2014 18:49:16 +0800 (CST)
  subject:Test mail
  Message-Id:<20140310104939.A68ED41BFB3@mail.tarena.com>
  Date: Mon, 10 Mar2014 18:49:16 +0800 (CST)
  From:nick@tarena.com
  To:undisclosed-recipients:;
  

  this is a test mail...
  .
  quit
  +OK Logging out.
  Connection closed byforeign host.
  #
  

  需要注意的几点:
  1,在安装postfix之前,需要先停了sendmail服务,同样的邮件软件,占用的端口都是25,如果不停用,可能会导致无法启动postfix;
  2,postfix是发送邮件的服务,dovecot是接收邮件的服务,两个软件合起来才能完成发送和接受的服务,所以需要完成两个部分的安装和配置;
  3,在做测试的过程中,可以通过一个windows的客户端,安装foxmail软件,在foxmail中建立账户,互发和接受信件,进行测试!
  

  扩展:邮件服务器的安全
  1:SMTP认证控制:http://murongqingqqq.blog.51cto.com/2902694/1372074
  2:搭建Webmail系统:http://murongqingqqq.blog.51cto.com/2902694/1372074

  

  
页: [1]
查看完整版本: Linux网络服务_邮件服务器