在这里祝大家五一节快乐!劳动最光荣qwq!

*这是由Google Adsense推荐的一个广告,并不代表本站的观点。

现在国内域名邮箱超级难申请,他娘的气死我了(在这里严厉批评QQ邮箱在2020年1月的时候关闭域名邮箱注册!还要在这里严厉批评Pingly的sb策略!)

阿里云企业邮和腾讯云企业邮蛋疼啊!

好了,没有办法,只好找个方法自建私人邮局

然后Postfix和Dovecot出现了~

Postfix负责SMTP,而Dovecot负责搞♂IMAP和POP3

正好手上有闲着的VPS,拿来用用

如果没有可以看看我以前的文章

先看好你的那台VPS的IP

然后去DNS地方改一下MX记录,像这样(Mail后缀也必须加VPS IP的A记录)

然后接上那个VPS的SSH,开始淦吧QAQ

首先还不是先去安装postfix和dovecot啊

//Fodera&RHEL&CentOS
yum -y install postfix dovecot
//Ubuntu&Debian
apt-get -y install postfix dovecot-common dovecot-imapd dovecot-pop3d

然后取消iptables的策略

systemctl disable iptables

或者是ufw

systemctl disable ufw

或者是firewalld

systemctl disable firewalld

如果有这些东西记得stop后再淦

Tips:阿里云ECS默认25端口被封,有一些主机都是这样,请擦亮眼睛,如果想要发邮件,请找其他的QAQ。

(我这个闲置的机子是ubuntu的,centos的也差不多)

root@pan:~# systemctl stop ufw
root@pan:~# systemctl disable ufw
Synchronizing state of ufw.service with SysV init with /lib/systemd/systemd-sysv-install...
Executing /lib/systemd/systemd-sysv-install disable ufw
insserv: warning: current start runlevel(s) (empty) of script `ufw' overrides LSB defaults (S).
insserv: warning: current stop runlevel(s) (1 S) of script `ufw' overrides LSB defaults (1).
insserv: warning: current start runlevel(s) (empty) of script `ufw' overrides LSB defaults (S).
insserv: warning: current stop runlevel(s) (1 S) of script `ufw' overrides LSB defaults (1).
root@pan:~# 

(Tips:Ubuntu安装postfix时候可能会蹦出postfix设置,选择Internet Site,等下我们要更改conf)

root@pan:~# apt-get -y install postfix dovecot-common dovecot-imapd dovecot-pop3d
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'dovecot-core' instead of 'dovecot-common'
The following additional packages will be installed:
  libexttextcat-2.0-0 libexttextcat-data ssl-cert
Suggested packages:
  ntp dovecot-gssapi dovecot-sieve dovecot-pgsql dovecot-mysql dovecot-sqlite dovecot-ldap dovecot-lmtpd dovecot-managesieved dovecot-solr procmail
  postfix-mysql postfix-pgsql postfix-ldap postfix-pcre sasl2-bin postfix-cdb mail-reader postfix-doc openssl-blacklist
The following NEW packages will be installed:
  dovecot-core dovecot-imapd dovecot-pop3d libexttextcat-2.0-0 libexttextcat-data postfix ssl-cert
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 3,939 kB of archives.
After this operation, 12.6 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu xenial/main amd64 libexttextcat-data all 3.4.4-1ubuntu3 [164 kB]
Get:2 http://archive.ubuntu.com/ubuntu xenial/main amd64 libexttextcat-2.0-0 amd64 3.4.4-1ubuntu3 [13.1 kB]
Get:3 http://archive.ubuntu.com/ubuntu xenial/main amd64 ssl-cert all 1.0.37 [16.9 kB]
Get:4 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 dovecot-core amd64 1:2.2.22-1ubuntu2.12 [2,422 kB]
Get:5 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 dovecot-imapd amd64 1:2.2.22-1ubuntu2.12 [143 kB]
Get:6 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 dovecot-pop3d amd64 1:2.2.22-1ubuntu2.12 [28.4 kB]
Get:7 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 postfix amd64 3.1.0-3ubuntu0.3 [1,152 kB]
Fetched 3,939 kB in 9s (426 kB/s)  
Preconfiguring packages ...
Selecting previously unselected package libexttextcat-data.
(Reading database ... 129955 files and directories currently installed.)
Preparing to unpack .../libexttextcat-data_3.4.4-1ubuntu3_all.deb ...
Unpacking libexttextcat-data (3.4.4-1ubuntu3) ...
Selecting previously unselected package libexttextcat-2.0-0:amd64.
Preparing to unpack .../libexttextcat-2.0-0_3.4.4-1ubuntu3_amd64.deb ...
Unpacking libexttextcat-2.0-0:amd64 (3.4.4-1ubuntu3) ...
Selecting previously unselected package ssl-cert.
Preparing to unpack .../ssl-cert_1.0.37_all.deb ...
Unpacking ssl-cert (1.0.37) ...
Selecting previously unselected package dovecot-core.
Preparing to unpack .../dovecot-core_1%3a2.2.22-1ubuntu2.12_amd64.deb ...
Unpacking dovecot-core (1:2.2.22-1ubuntu2.12) ...
Selecting previously unselected package dovecot-imapd.
Preparing to unpack .../dovecot-imapd_1%3a2.2.22-1ubuntu2.12_amd64.deb ...
Unpacking dovecot-imapd (1:2.2.22-1ubuntu2.12) ...
Selecting previously unselected package dovecot-pop3d.
Preparing to unpack .../dovecot-pop3d_1%3a2.2.22-1ubuntu2.12_amd64.deb ...
Unpacking dovecot-pop3d (1:2.2.22-1ubuntu2.12) ...
Selecting previously unselected package postfix.
Preparing to unpack .../postfix_3.1.0-3ubuntu0.3_amd64.deb ...
Unpacking postfix (3.1.0-3ubuntu0.3) ...
Processing triggers for libc-bin (2.23-0ubuntu11) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for ufw (0.35-0ubuntu2) ...
Processing triggers for ureadahead (0.100.0-19.1) ...
Processing triggers for systemd (229-4ubuntu21.27) ...
Setting up libexttextcat-data (3.4.4-1ubuntu3) ...
Setting up libexttextcat-2.0-0:amd64 (3.4.4-1ubuntu3) ...
Setting up ssl-cert (1.0.37) ...
Setting up dovecot-core (1:2.2.22-1ubuntu2.12) ...

Creating config file /etc/dovecot/dovecot.conf with new version

Creating config file /etc/dovecot/dovecot-dict-auth.conf.ext with new version

Creating config file /etc/dovecot/dovecot-dict-sql.conf.ext with new version

Creating config file /etc/dovecot/dovecot-sql.conf.ext with new version

Creating config file /etc/dovecot/conf.d/10-auth.conf with new version

Creating config file /etc/dovecot/conf.d/10-director.conf with new version

Creating config file /etc/dovecot/conf.d/10-logging.conf with new version

Creating config file /etc/dovecot/conf.d/10-mail.conf with new version

Creating config file /etc/dovecot/conf.d/10-master.conf with new version

Creating config file /etc/dovecot/conf.d/10-tcpwrapper.conf with new version

Creating config file /etc/dovecot/conf.d/15-lda.conf with new version

Creating config file /etc/dovecot/conf.d/15-mailboxes.conf with new version

Creating config file /etc/dovecot/conf.d/90-acl.conf with new version

Creating config file /etc/dovecot/conf.d/90-plugin.conf with new version

Creating config file /etc/dovecot/conf.d/90-quota.conf with new version

Creating config file /etc/dovecot/conf.d/auth-checkpassword.conf.ext with new version

Creating config file /etc/dovecot/conf.d/auth-deny.conf.ext with new version

Creating config file /etc/dovecot/conf.d/auth-dict.conf.ext with new version

Creating config file /etc/dovecot/conf.d/auth-master.conf.ext with new version

Creating config file /etc/dovecot/conf.d/auth-passwdfile.conf.ext with new version

Creating config file /etc/dovecot/conf.d/auth-sql.conf.ext with new version

Creating config file /etc/dovecot/conf.d/auth-static.conf.ext with new version

Creating config file /etc/dovecot/conf.d/auth-system.conf.ext with new version

Creating config file /etc/dovecot/conf.d/auth-vpopmail.conf.ext with new version
Setting up dovecot-imapd (1:2.2.22-1ubuntu2.12) ...

Creating config file /etc/dovecot/conf.d/20-imap.conf with new version
Setting up dovecot-pop3d (1:2.2.22-1ubuntu2.12) ...

Creating config file /etc/dovecot/conf.d/20-pop3.conf with new version
Setting up postfix (3.1.0-3ubuntu0.3) ...
Adding group `postfix' (GID 119) ...
Done.
Adding system user `postfix' (UID 111) ...
Adding new user `postfix' (UID 111) with group `postfix' ...
Not creating home directory `/var/spool/postfix'.
Creating /etc/postfix/dynamicmaps.cf
Adding group `postdrop' (GID 120) ...
Done.
/etc/aliases does not exist, creating it.

Postfix was not set up.  Start with
  cp /usr/share/postfix/main.cf.debian /etc/postfix/main.cf
.  If you need to make changes, edit
/etc/postfix/main.cf (and others) as needed.  To view Postfix configuration
values, see postconf(1).

After modifying main.cf, be sure to run '/etc/init.d/postfix reload'.

Processing triggers for libc-bin (2.23-0ubuntu11) ...
Processing triggers for ureadahead (0.100.0-19.1) ...
Processing triggers for systemd (229-4ubuntu21.27) ...
Processing triggers for ufw (0.35-0ubuntu2) ...
Processing triggers for dovecot-core (1:2.2.22-1ubuntu2.12) ...
root@pan:~# 

postfix的设置地址是/etc/postfix/main.cf

(Tips:如果找不到,请输入以下这个东东QAQ)

cp /etc/postfix/main.cf.proto /etc/postfix/main.cf

然后有一些参数这里列出来,自己去根据实际情况改改就行qwq

参数作用
myhostname邮局主机名(例如mail.moekonnyaku.com)
mydomain邮局的域名(例如moekonnyaku.com)
myorigin从这里发送出去的域名(例如moekonnyaku.com)
inet_interfaces一般填all就行
mydestination可接受邮件的主机名(一般填$mydomain就行)
mynetworks可以转发哪里的邮件(一般填all)也可以不动
relay_domains可以转发哪些域名的邮件(一般填all)也可以不动

这个是CSDN设置的QAQ可以看看

myhostname = localhost
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
 
#下面这段配置中要将自己的域名加入到里面,如下加入了example.cn
mydestination = $myhostname, example.cn,localhost, localhost.localdomain, localhost
relayhost =
#加入公网的网络地址,如我的服务器公网地址是119.xxx.xxx.xxx,就在下面加入了
119.0.0.0/8这个网络地址
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104[::1]/128,119.0.0.0/8
#邮箱最大的容量,单位是字节
mailbox_size_limit = 2000000000
recipient_delimiter = +
#监听的端口设置,如果要连互联网这里一定设置成all
inet_interfaces = all
#支持的协议类型,设置成all
inet_protocols = all
#设置的邮箱目录名称,postfix采用dovecot-auth认证的话,默认系统中的用户就是邮箱的用户,当设置成如下的邮箱目录时,会在每个用户的主目录下创建一个Maildir目录用来存放邮件。
home_mailbox = Maildir/
#设置每封邮件最大的体积
message_size_limit = 20000000
#设置是否进行认证,选yes
smtpd_sasl_auth_enable = yes
#设置认证失败断开客户端
broken_sasl_auth_clients = yes
#设置认证所在的域名
smtpd_sasl_local_domain = $myhostname
#设置认证方式,这里很重要,因为要使用dovecot-auth,所以这里要填dovecot
smtpd_sasl_type = dovecot
#设置认证文件的查询路径,默认情况下Postfix的认证文件会放到/var/spool/postfix/private/auth,按照如下设置即可
queue_directory = /var/spool/postfix
smtpd_sasl_path =private/auth
#设置未认证用户不可发邮件
smtpd_sasl_security_options = noanonymous
#设置拒绝认证的黑名单,在postfix2.02之前的版本,该配置名称叫做smtpd_recipient_restrictions
smtpd_relay_restrictions=permit_mynetworks,
 permit_sasl_authenticated,
 reject_invalid_hostname,
 reject_unauth_destination
 
#下面是设置对tls的支持,在安装完之后ssl-cert-snakeoil.pem和ssl-cert-snakeoil.key这两个文件是不存在的,需要我们手动生成,稍后介绍生成方法
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database =btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database =btree:${data_directory}/smtp_scache
原文链接:https://blog.csdn.net/hyman_c/article/details/64474151

然后就可以用了~但是现在我们还没有完成Dovecot的设置QAQ

(Tips:下面的Dovecot暂时没有设置!总是出错!等着下一次!)

所以我们还要搞Dovecot

Dovecot的设置地址在/etc/dovecot/dovecot.conf

然后给大家几个参数自己去体会QAQ(转自CSDN)

#这里配置邮件的存放目录,这里和Postfix设置的要一致,都是在用户主目录下的Maildir目录下。
mail_location = maildir:~/Maildir
#监听所有的端口
listen= *
#允许明文密码验证
disable_plaintext_auth = no
#使用ssl加密
ssl = required
#ssl秘钥存放路径,目前这两个文件也是不存在的,也需要按照后面的步骤我们手动生成
ssl_cert =< /etc/ssl/certs/dovecot.pem
ssl_key =< /etc/ssl/private/dovecot.key
#设置认证的默认选项,auth是一个socket文件,通过该文件dovecot和postfix进行通信,来传递postfix的认证信息,这里面的path要和postfix设置的一致。
auth default { 
       socket listen {
         client {
           path =/var/spool/postfix/private/auth
           mode = 0660
           user = postfix
           group = postfix
         }
     }
}
原文链接:https://blog.csdn.net/hyman_c/article/details/64474151

Tips:为了安全起见,我们要生成密钥(下面转自CSDN,我不会搞♂[难过])

3.3 生成postfix的tsl秘钥和dovecot的ssl秘钥
        接下来我们需要利用dovecot安装包中的脚本上次上述两种秘钥。目前存放秘钥的目录/etc/ssl/certs/和/etc/ssl/ private/也是不存在的,所以需要我们先创建上述两个目录:

mkdir –p /etc/ssl/certs/
mkdir –p /etc/ssl/private /
         创建好上述的目录之后我们将利用dovecot中的脚本文件,生成ssl-cert-snakeoil.pem、ssl-cert-snakeoil.key、dovecot.pem和dovecot.key这四个文件。因为我们用apt-getinstall安装的dovecot,所以我们先要进入/ var/cache/apt/archives/这个目录下。我们用apt-getinstall        安装的所有程序的安装包都在这个目录下,找到dovecot-core***.deb安装包(后面版本号什么的省略),把它拷贝到主目录下,然后用下面的命令进行解压:

dpkg –X dovecot-core***.deb dovecot/
        解压之后,在当前目录找到dovecot/usr/share/dovecot/ mkcert.sh,然后执行下面的命令(一定要cd到该文件所在目录去执行,否则出错):

sh mkcert.sh
        此时会在/etc/ssl/certs/目录和/etc/ssl/private/目录下生成ssl-cert-snakeoil.pem和ssl-cert-snakeoil.key两个文件,这就是我们需要的postfix的tls秘钥,我们需要的dovecot秘钥只需将上述两个文件各拷贝一份副本即可:

cp ssl-cert-snakeoil.pem dovecot.pem
cp ssl-cert-snakeoil.key dovecot.key
        这就完成相关秘钥的生成。
————————————————
版权声明:本文为CSDN博主「HymanLiuTS」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/hyman_c/article/details/64474151

这些配置好之后重启然后设置一下开机启动

systemctl enable dovecot
systemctl enable postfix
systemctl restart postfix
systemctl restart dovecot

然后在里面加入自己想要的名字就行

useradd chihuo2104

当这个的话就是chihuo2104@moekonnyaku.com了

然后打开邮箱啥的,账号就是这个,服务器选择mail.xxx.com然后就行

密码是你设置的linux密码

如果忘记了,可以用root更改一下

passwd chihuo2104

科技为主,游戏为辅。技术肥宅,喜欢看番。