← 返回

Debian Linux 7.0个人邮件服务器搭建指南

1、准备工作 a) 顶级域名(不限注册商),假设为test.com b) 个人电脑一台(用作服务器) c) 带花生壳DDNS功能路由器一台,假设壳域名为:test.vicp.cc 2、域名解析

Type

Host

Answer

TTL

Prio

CNAME

*.test.com

test.vicp.cc

60

N/A

MX

test.com

mx.test.com

300

10

TXT

test.com

v=spf1 a mx ~all

300

N/A

3、路由器设置 a) 在路由器管理页面登陆花壳帐号 b) 在路由器中设置端口映射 4、服务器配置 a) 安装操作系统,本文以Debian Linux 7.0为例 b) 安装软件

# apt-get update
# apt-get install sendmail dovecot-imapd dovecot-core dovecot-pop3d apache2 php5

c) 修改主机名 修改/etc/hostname文件,将内容改为:test.com,之后运行以下命令:

# hostname -F /etc/hostname

修改/etc/hosts文件,在127.0.0.1字段后加test.com 5、软件配置 a) Sendmail 配置文件目录:/etc/mail 需改动配置文件:sendmail.mc access local-host-names >sendmail.mc

DAEMON_OPTIONS(`Family=inet,  Name=MTA-v4, Port=smtp, Addr=0.0.0.0')dnl #原文本为127.0.0.1,改动后smtp服务器对所有IP可用。
dnl MASQUERADE_AS(`localhost')dnl #注释该行,即在前面加dnl,等同于下面修改sendmail.cf文件。

改动sendmail.mc后运行命令:

# cd /etc/mail
# m4 sendmail.mc > sendmail.cf

>sendmail.cf

# DMlocalhost  #原文本没有注释,如不改动,发件地址为test@localhost

>access 加入允许发送邮件的域名,如:

sina.com RELAY
google.com RELAY
qq.com RELAY

运行以下命令:

# makemap hash access.db < access

>local-host-names 添加: test.com 重启sendmail服务:

Bash

# /etc/init.d/sendmail restart

b) Dovecot 配置文件目录:/etc/dovecot/conf.d 需修改文件:10-auth.conf, 10-mail.conf, 10-master.conf, 10-ssl.conf >10-auth.conf 取掉以下行注释

disable_plaintext_auth = yes

>10-mail.conf 更改收件箱位置

Markup

mail_location = mbox:~/mail:INBOX=/var/mail/%u

%u - 用户名 %n - 主机名user@domain的用户名部分,如果没有则等同于%u %d - 主机名user@domain的域名部分,如果没有则为家 %h -  家目录 以下是三种格式 mail_location = maildir:/Maildir mail_location = mbox:/mail:INBOX=/var/mail/%u mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n 关于maildir和mbox的优缺点,请自行搜索,就大致而言,maildir是将邮件放在一个目录,而mbox则是存在一个文本文件中。笔者的配置为:“mail_location = maildir:~/mail” >10-master.conf

service imap-login {
    inet_listener imap {
        port = 0
        #port = 143
    }
    inet_listener imaps {
        port = 993
        ssl = yes
    }
}
                    
service pop3-login {
    inet_listener pop3 {
        port = 0
        #port = 110
    }
    inet_listener pop3s{
        port = 0
        #port = 995
        #ssl = yes
    }
}

只用到imaps,所以关闭了imap, pop3, pop3s的端口监听,方法是在对应的大括号中添加“port = 0”。 >10-ssl.conf

ssl = yes
ssl_cert = </etc/dovecot/dovecot.pem
ssl_key = </etc/dovecot/private/dovecot.pem
ssl_ca = </etc/ssl/certs/ca.pem

取掉以上三行注释,重启dovecot服务

# /etc/init.d/dovecot restart

有关配置ssl dovecot,请参考: http://wiki2.dovecot.org/SSL/DovecotConfiguration c) Apache2 配置文件目录:/etd/apache2 下载SquirrelMail并解压到/var/www目录下(也可自行更改为子文件夹) 有关虚拟主机配置,请参考本博客其它文章 6、邮箱帐户设置 a) 添加帐号

# useradd -m test

b) 更改帐号密码

Bash

# passwd test

7、收发件测试

# echo “hello world” | sendmail -v test@test.com

PS:用花生壳转发的邮箱如果配置正确,可以正常收到其它邮箱发来的邮件,但发送到大多数域名(如:sina.com, google.com, qq.com)的邮件将会被拒收,原因是动态IP被收录在类似一个邮垃圾邮件IP名单中,楼主没找到解决方法,暂时花钱买了VPS奢侈一把。 8、如果出现“Error connecting to IMAP server "localhost:993".Server error: (111) Connection refused”错误,请安装dovecot-pop3d, dovecot-imapd。

Comments

Loading comments...

Leave a comment