zoukankan      html  css  js  c++  java
  • linux 邮件服务器

    邮件通信系统协议及概念:
    软件角色:
    MUA:邮件客户端
    MTA:邮件服务端
    MDA:邮件服务端模块
    邮件客户端:Mail User Agent,邮件用户代理
    邮件服务端:Mail Transfer Agent,邮件传输代理
    邮件服务端的模块/功能:Mail Delivery Agent,邮件分发代理

    发送,投递邮件——Postfix
    收取邮件——Dovecot

    通信协议及过程:
    邮件传递双方的通信规则
    SMTP:简单邮件传输协议(TCP25)
    POP3:离线取信协议,第三版邮件协议(TCP110)
    IMAP4:在线管理信件协议,第四版网际消息访问协议(TCP143)
    发件人—SMTP—》MTA—SMTP—》MTA—POP3/IMAP—MUA

    常见的邮件服务器软件
    Ppostfix
    兼容Sendmail,采用模块化设计
    在投递效率,稳定性,性能及安全方面均表现出色
    Exchange
    微软公司产品,方便与windows系列产品集成,协作性好
    其他开源MTA软件
    Qmail Sendmail

    邮件客户端软件
    命令行工具
    telnet 邮件服务器 端口
    mail mutt
    图形收发信软件工具
    microsoft outlook
    Tencent foxmail
    mozilla thunderbird(雷鸟)

    ————————————————————————————————

    邮件系统构成
    发信服务+收信服务+客户端工具

    案例:
    邮件服务器:mail.Anonymous.cn 192.168.4.6
    邮件域:@Anonymous.cn
    邮件账号:服务器的本地系统用户
    主要软件
    发信服务:postfix
    收信服务:dovecot
    MX(Mail exXchange 邮件交换记录)
    [root@svr6 ~]# useradd x(创建两用户)
    [root@svr6 ~]# useradd xx

    [root@svr6 named]# vim /etc/named.conf
    options {
    directory "/var/named";
    };
    zone "Anonymous.cn" {
    type master;
    file "Anonymous.cn.zone";
    };

    [root@svr6 named]# vim Anonymous.cn.zone
    @ MX 10 mail.Anonymous.cn.(@ MX 优先级 邮件服务器的fqdn)
    mail A 192.168.4.6(邮件服务器地址)
    [root@pc05]# service named restart

    发信服务:Postfix:
    在redhat6,postfix已经默认安装,但是监听地址是127.0.0.1:25
    相关目录及配置文件
    配置文件,存放在/etc/postfix/下
    服务配置:/etc/postfix/main.cf
    主程序配置:/etc/postfix/master.cf
    管理程序,存放在/usr/sbin/下
    postalias,postmap,postconf,postfix,postqueue,postsuper

    邮件通信日志(排错依据):
    /var/log/maillog
    邮件队列目录,/var/spool/postfix子目录
    incoming,active,deferred,hold,corrupt


    postconf:查看当前有效配置(所有可设置的项)
    postconf -d:查看所有默认配置(所有可设置的项)
    postconf -n:只列出修改过的配置(非默认)
    postconf -e 'inet_interfaces = all'(直接改选项)
    [root@svr6 postfix]# postconf

    服务接口及域设置:
    基本配置参数
    inet_interfaces:监听服务的接口地址
    myhostname:服务器主机名
    mydomain:主邮件域
    myorigin:外发邮件时的发邮件域地址
    mydestination:能够本地投递的收件域

    邮箱类型及位置:
    邮箱类型
    mbox:每个用户一个邮箱文件,存放所有的邮件消息,当邮件内容较多时效率较低
    ——》传统邮箱:/var/spool/mail/用户名
    maildir:每个用户一个邮箱目录,每封邮件对应一个单独的文件,存取速度和效率更好,管理邮件内容更加方便
    home_mailbox:邮箱位置及类型
    [root@svr6 postfix]# vim main.cf
    home_mailbox = Maildir(采用Maildir邮箱类型)
    Ps:其中maildir表示邮箱名称,放在用户宿主目录下,当收到第一封邮件后会自动创建。
    末尾的 / 表示此邮箱是一个目录(非mailbox方式)

    精简配置文件
    [root@svr6 postfix]# cp main.cf main.bak(安全起见,备份默认的配置文件)
    [root@svr6 postfix]# mv a.txt main.cf (覆盖原有的配置文件)
    mv:是否覆盖"main.cf"? y(y)
    [root@svr6 postfix]# vim main.cf (修改main.cf)
    inet_interfaces = all(开启)
    mydomain = Anonymous.cn(主邮件域)
    myhostname = mail.$mydomain($mydomain变量,相当于mail.Anonymous.cn)
    myorigin = $mydomain
    mydestination = $mydomain,$myhostname, localhost.$mydomain, localhost(加上$mydomain变量)
    home_mailbox = Maildir/
    [root@svr6 ~]# service postfix restart(配置好后,重启服务)

    MUA客户端软件
    mail命令:不需要任何配置,直接在本机作为邮件服务器
    只要做必要的配置,可以以其他主机作为邮件服务器
    mail用法:
    发信:mail -s '标题' -r 发件人地址 收件人地址
    echo '文件'| mial -s '标题' -r 发件人地址 收件人地址
    mial -s '标题' -r 发件人地址 收件人地址 < 文件目录/文件

    [root@svr6 ~]# mail -s 'hydra' -r xx@Anonymous x@Anonymous.cn(实例)
    hail hydra!!(写完后ctrl+d发送)

    [root@svr6 ~]# echo 'hail hydra'|mail -s 'hydra' -r xx@Anonymous.cn x@Anonymous.cn(管道方式发送)

    [root@svr6 ~]# mail -s 'hydra' -r xx@Anonymous.cn x@Anonymous.cn < /etc/passwd(邮件内容较多时,可以先把邮件写好封装在文件中,用<重定向输入)

    收信:
    [root@svr6 ~]# ls ~x/(进入x的家目录)
    Maildir
    [root@svr6 ~]# ls ~x/Maildir/(新邮件放在new下)
    cur/ new/ tmp/
    [root@svr6 ~]# ls ~x/Maildir/new/
    1499966759.Vfd00I100928M340082.svr6.tedu.cn
    1499967055.Vfd00I10092bM763659.svr6.tedu.cn
    1499967565.Vfd00I10092cM389136.svr6.tedu.cn
    [root@svr6 ~]# cat ~x/Maildir/new/1499966759.Vfd00I100928M340082.svr6.tedu.cn(查看邮件内容)
    Return-Path: <root@Anonymous.cn>
    X-Original-To: x@Anonymous.cn
    Delivered-To: x@Anonymous.cn
    Received: by mail.Anonymous.cn (Postfix, from userid 0)
    id 16DF618061E; Fri, 14 Jul 2017 01:25:58 +0800 (CST)
    Date: Fri, 14 Jul 2017 01:25:58 +0800
    To: x@Anonymous.cn
    Subject: hydra
    User-Agent: Heirloom mailx 12.4 7/29/08
    MIME-Version: 1.0
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    Message-Id: <20170713172559.16DF618061E@mail.Anonymous.cn>
    From: root@Anonymous.cn (root)

    ————————————————————————————————————
    C/S架构
    从邮件服务器本机来发信,收信
    svr6上的mail——》svr6上的postfi
    svr6上的mail——》svr6上的邮箱目录
    从客户机来收信,发信(使用刚搭建的邮件服务器)
    pc05上的mail——》svr6上的postfi
    pc05上的mail——》svr6上的dovecot(邮箱目录)

    构建dovecot收信服务:
    安装dovecot软件包,默认支持POP3,IMAP这两种收信协议,
    根据需要,可将其设为开机自启
    [root@svr6 ~]# yum -y install dovecot
    [root@svr6 ~]# vim /etc/dovecot/conf.d/10-auth.conf
    disable_plaintext_auth = no(允许明文通信)
    [root@svr6 ~]# vim /etc/dovecot/conf.d/10-mail.conf
    mail_location = maildir:~/Maildir(用户邮件存放目录)

    SMTP认证的工作方式:
    Simple Authentication and Security Layer
    cyrus-sas-plain 软件包(默认安装)
    [root@svr6 ~]# rpm -qa | grep cyrus
    cyrus-sasl-plain-2.1.23-15.el6_6.2.x86_64
    cyrus-sasl-2.1.23-15.el6_6.2.x86_64
    cyrus-sasl-lib-2.1.23-15.el6_6.2.x86_64

    SMTP认证的实现:
    启动saslauthd服务
    [root@svr6 ~]# service saslauthd restart
    [root@svr6 ~]# chkconfig saslauthd on

    调整postfix配置,添加认证控制参数
    [root@svr6 ~]# vim /etc/postfix/main.cf
    smtpd_sasl_auth_enable = yes(启用SASL认证)
    mynetworks = 127.0.0.1(设置信任网络)
    smtpd_sasl_security_options = noanonymous(阻止匿名发信)
    smtpd_recipient_restrictions = (设置收件人过滤)
    permit_mynetworks,
    permit_sasl_authenticated,
    reject_unauth_destination (拒绝向未授权的目标发信)


    配置mail客户端:
    命令行
    在客户机上为mail命令建立配置文件,
    /etc/mail.rc或者~/.mailrc
    [root@pc05 ~]# vim ~./mailrc
    set smtp=smtp://mail.Anonymous.cn(发信服务器)
    set from=x@Anonymous.cn(发件人地址)
    set smtp-auth-user=x@Anonymous.cn(指定认证用户)
    set smtp-auth-password="Taren1"(指定认证密码)
    set folder=imap://Anonymous.cn(收信服务器地址)
    set password-x@Anonymous.cn="Taren1"(收信密码)

    邮件图形界面thunderbird(雷鸟)

    ——————————————————————————————————

  • 相关阅读:
    Spring过滤器和拦截器 2017-12-20
    集合
    用LinkedList方法模拟栈的数据结构
    集合遍历时,修改元素
    Calendar日历类,简单的时间获取
    java中日期与字符串之间的转换
    UIViewController生命周期
    属性传值和代理传值的步骤
    UITableView的详细使用
    UIAlertView的使用方法
  • 原文地址:https://www.cnblogs.com/Hydraxx/p/7197255.html
Copyright © 2011-2022 走看看