仝 tóng

Postfix+Dovecot:Build Your Own Mail Server

How to create your own email server use linux, first, you need a vps server with a external IP address, and next you only need to config postfix to send and receive your email.
we use CentOS as an example:

  1. logging into you centos vps server, try next command

yum remove sendmail -y // remove sendmail if this exist

yum install postfix dovecot -y // install postfix and dovecot

  1. we need to config postfix

cd /etc/postfix

vim main.cf

find out #myhostname and change it to your hostname like "example.com"
next is the full change of this file:
myhostname = example.com // or mail.example.com
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 192.168.0.0/24, 127.0.0.0/8
relay_domains =
home_mailbox = Maildir/
smtpd_sasl_auth_enable = yes
broken_sasl_auth_clients = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_security_options = noanonymous
smtpd_recipient_restrictions =
permit_mynetworks,
permit_sasl_authenticated,
reject_unauth_destination
exit and save file.
if you want all the coming email forward to a local user, you should add this to main.cf
luser_relay = example_user
local_recipient_maps =
and forward the root emails to example_user too

vim /etc/aliases

find at last

Person who should get root's mail

root: example_user
save it and type this command
$ newaliases
$ service postfix restart
all the incoming emails forwording to example_user
3.config dovecot

vim /etc/dovecot/dovecot.conf

Uncomment and edit this line

protocols = imap pop3

vim /etc/dovecot/10-auth.conf

Uncomment and edit

disable_plaintext_auth = no
auth_mechanisms = plain login

vim /etc/dovecot/conf.d/10-master.conf

Edit and change it to // add it to #Postfix smtp-auth

unix_listener /var/spool/postfix/private/auth {
mode = 0660

Assuming the default Postfix user and group

user = postfix
group = postfix

vim 10-mail.conf //if this file exist

line 30
change mail_location =
to
mail_location = maildir:~/Maildir
// change dovecot log path

vim /etc/dovecot/conf.d/10-logging.conf

log_path = /var/log/dovecot.log
auth_verbose = yes
mail_debug = yes

  1. create a new user to accept mails

useradd -s /sbin/nologin exampleuser

passwd exampleuser

  1. restart postfix and dovecot

service postfix restart

service dovecot restart

  1. let use telnet to have a test or use mail ender software

yum install telnet -y

telnet localhost smtp

mail from:

rcpt to:

data

this is a test email

. // do not forget this dot .

quit

cd /home/exampleuser/Maildir/new // you will find your email here

  1. test doveot is working well

telnet localhost pop3

Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.

user exampleruser

+OK

pass password

+OK Logged in.
retr 1
+OK 357 octets
it's working well.
that's it.

发表新评论