步骤1:安装必要的包。
我们需要做的第一件事是为我们的邮件服务器安装包。
作为根用户执行以下操作。
apt-get install postfix dovecot-imapd dovecot-managesieved sendmail mailutils -y
“-y”是apt-get的一个参数,它允许我们自动接受确认。
当您收到“后缀配置”提示时,按下“Tab”键,然后输入“Enter”键,最后再一次输入“Enter”键,以设置后缀为Internet站点。
然后,您需要输入您的主域,然后点击“enter”键。
步骤2:配置Dovecot和Postfix。
我们需要首先对系统使用的电子邮件地址进行配置,以发送拒绝邮件(如弹出邮件)。
在您喜欢的文本编辑器中打开 /etc/dovecot/conf.d/15-lda.conf.文件 ,找到看起来像
#postmaster_address =www.banwagongvps.com/843.html
.改变它。
postmaster_address = postmaster@%d
保存并退出。
接下来,打开
/etc/postfix/main.cf
滚动到底部,并添加以下内容。
mailbox_command = /usr/lib/dovecot/deliver
或者,您可以在shell提示中输入这个。
步骤3:配置启动服务。
理想情况下,我们想要自动地启动Postfix和Dovecot。输入以下命令,告诉SystemD自动启动它们。
systemctl enable postfix
systemctl enable dovecot
现在,让我们重新启动它们以应用任何配置更改。
systemctl restart postfix
systemctl restart dovecot
步骤4:测试服务器并安装SSL。
让我们来测试一下我们目前所做的工作,以确保一切正常。
echo "Testmail!" | mail -s "Testmail!" root@localhost
您应该找到类似于/var/log/mail.log中的消息。
install postfix/local[10309]: A0B361DDA2: to=<root@localhost>, relay=local, delay=0.02, delays=0.01/0/0/0.01, dsn=2.0.0, status=sent (delivered to command: /usr/lib/dovecot/deliver
现在基本的服务已经开始工作了,还有两个重要的事情要做。互联网不是一个友好的地方,使加密尽可能成为必要。在本例中,我们将使用SSL/TLS。理想情况下,您应该拥有来自可信CA的证书——例如,让我们加密,在那里您可以获得免费的证书。对于私人使用,自签名证书也很好。
您可以使用以下命令生成自签名证书。
mkdir /etc/dovecot/private
openssl req -newkey rsa:4096 -sha512 -x509 -days 365 -nodes -keyout /etc/dovecot/private/mykey.key -out /etc/dovecot/mycert.pem
chmod 600 /etc/dovecot/private/*
将以下内容附加到/etc/postfix/main.cf。
smtpd_tls_cert_file = /etc/dovecot/private/mykey.pem
smtpd_tls_key_file = /etc/dovecot/private/mycert.pem
smtpd_use_tls = yes
保存、退出并重新启动Postfix.
systemctl restart postfix
现在,打开./etc/dovecot/conf.d/10-ssl.conf文件
更改配置文件中的值。
ssl = yes
ssl_key = /etc/dovecot/private/mykey.pem
ssl_cert = /etc/dovecot/private/mycert.pem
重启Dovecot
systemctl restart dovecot
测试SSL功能。
openssl s_client -starttls smtp -crlf -connect domainYouEnteredEarlierInStep1:25
如果答案包含证书和连接信息,那么一切都正常工作。本教程的最后一步是配置筛选器。使用您最喜欢的文本编辑器打开/etc/dovecot/conf.d/15-lda. 并编辑下面的行。
mail_plugins = $mail_plugins sieve
最后一个重启。
systemctl restart dovecot
步骤5(可选):作为无特权用户发送/接收邮件。
使用根用户发送/接收电子邮件被认为是不专业的。为了解决这个问题,我们将创建一个非特权用户。
useradd -m myUser #-m is a parameter that forces the creation of the home directory
passwd myUser
恭喜你,你在VPS上设置了一个邮件服务器。
来源于百度百家号:http://baijiahao.baidu.com/builder/preview/s?id=1625786069468541001