介绍
这份指南将帮助你建立一个基本的企业级Postfix邮件服务器。主要目的是教会你如何安装和配置一个包含IMAP和POP3服务的基本Postfix邮件服务器。
安装概述
安装配置过程中,postfix通过Internet发送和接收emial,并存储在用户邮箱里。同时客户也可以通过IMAP或者POP3恢复他们的邮件。
安装Postfix
一开始我想你需要做的一件事是修改 hostname,虽然大多数参考资料不提这个,但是这里依然存在一个问题,就是 hostname 里面可能含有 test 之类的单词,这是你的mailserver 被spam 的可能原因之一,所以我干脆把 hostname 改成 mydomain.com 了。
In this setup I assume that your domain is yourdomain.com
and it has a valid MX record call mail.yourdomain.com
. Remember to replace yourdomain.com
with your actual domain in the example codes in this howto. Also I assume that you know what an MX record is. To find out MX your type in a terminal:
dig mx yourdomain.com
安装postfix
apt-get install postfix
安装mailx软件包 mailx软件包是一个命令行的邮件属性程序,mail命令包含在mailx软件包里面
apt-get install mailx
测试你的默认设置
首先添加一个用户. (这里以fmaster为例)
useradd -m -s /bin/bash fmaster sudo passwd fmaster
用下面的命令测试,其实就是测试25端口是否打开
telnet localhost 25
Postfix will prompt like following in the terminal so that you can use to type SMTP commands.
Trying 127.0.0.1...
Connected to mail.fossedu.org.
Escape character is '^]'.
220 localhost.localdomain ESMTP Postfix (Ubuntu)
用下面的命令测试postfix
ehlo localhost
mail from: root@localhost
rcpt to: fmaster@localhost
data
Subjet: My first mail on Postfix
Hi,
Are you there?
regards,
Admin
. (Type the .[dot] in a new Line and press Enter )
quit
检查刚才创建的fmaster
用户的收件箱
su – fmaster
When your type mail
command an output like follows display in your terminal.
Mail version 8.1.2 01/15/2001. Type ? for help.
"/var/mail/fmaster": 2 messages 2 new
>N 1 root@localhost Mon Mar 6 12:49 13/479 Just a test
N 2 root@localhost Mon Mar 6 12:51 15/487 My first mail
&
When your type mail
command an output like follows display in your terminal.
Mail version 8.1.2 01/15/2001. Type ? for help. “/var/mail/fmaster”: 2 messages 2 new >N 1 root@localhost Mon Mar 6 12:49 13/479 Just a test N 2 root@localhost Mon Mar 6 12:51 15/487 My first mail &
You will observe that mails are indexed by numbers and you can type the number of which the mail that you want to read. For example type no "2"
to read the 2nd mail. The type "q"
to quit. The mail will be written to a file called mbox
in user’s home directory. According to our example it will be /home/fmaster/mbox
.
All messages in an mbox type of mailbox are concatenated and stored in a single file. The beginning of each message is indicated by a line whose first five characters are “From ” and a blank line is appended to the end of each message
Setting Postfix Support for Maildir-style Mailboxes
Maildir is a format for an e-mail spool that does not require file locking to maintain message integrity because the messages are kept in separate files with unique names. A Maildir is a directory (often named Maildir) with three subdirectories named tmp, new, and cur. The subdirectories should all reside on the same filesystem.
Another reason to use Maildir format is that Courier IMAP/POP3 servers only work with Maildir format of mailboxes.
Please find out more about Maildir here
vi /etc/postfix/main.cf
Add the following code segment:
home_mailbox = Maildir/
Comment the Line mailbox_command = procmail -a "$EXTENSION"
adding a “#” at the beginning
Restart Postfix to make changes effect.
/etc/init.d/postfix restart
Test your setup again
Installing courier IMAP and POP3
sudo apt-get install courier-pop
sudo apt-get install courier-imap
[编辑] Adding local domains to postfix
vi /etc/postfix/main.cf
Add your domain to mydestination
. Once added it should be like the following code segment.
...
mydestination = mail.fossedu.org, localhost.localdomain, localhost, yourdoamin.com
...
Add your local network to:
vi /etc/postfix/main.cf
I assume that your local network is 192.168.1.0/24 and add your local network to mynetworks
. Once added it should be like the following code segment.
mynetworks = 127.0.0.0/8, 192.168.1.0/24
如果是独立静态IP地址,local IP 是 127.0.0.1,则:
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
Make Postfix to receive mail from the Internet
inet_interfaces = all
防止ralay
mynetworks_style = host
Finally Restart Postfix;
/etc/init.d/postfix restart