安裝配置Postfix
1 、安裝
- 驗證是否支持 cyrus dovecot 功能
[root@mail ~]# postconf -a
cyrus
dovecot
若postfix已安裝好,則會支持這兩個功能,若不支持,表示postfix未安裝好;CentOS 7開始默認系統自帶postfix
# 安裝postfix
yum -y install postfix
# 安裝完成還需要替換系統自帶的sendmail:
rpm -e sendmail 或 yum remove sendmail
# 修改MTA(默認郵件傳輸代理)
alternatives --config mta # 然後直接回車即可。
# 檢查一下是不是已經設置成功了。
alternatives --display mta #第一行可以看到mta的狀態。 例如:mat - status is manual.
- 開啓postfix服務並添加到系統自啓
[root@mail ~]# systemctl restart postfix
[root@mail ~]# systemctl enable postfix
[root@mail ~]# systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2020-01-15 10:00:45 CST; 5s ago
Process: 2097 ExecStop=/usr/sbin/postfix stop (code=exited, status=0/SUCCESS)
Process: 2110 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)
Process: 2108 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
Process: 2106 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS)
Main PID: 2182 (master)
CGroup: /system.slice/postfix.service
├─2182 /usr/libexec/postfix/master -w
├─2183 pickup -l -t unix -u
└─2184 qmgr -l -t unix -u
Jan 15 10:00:45 mail systemd[1]: Stopped Postfix Mail Transport Agent.
Jan 15 10:00:45 mail systemd[1]: Starting Postfix Mail Transport Agent...
Jan 15 10:00:45 mail postfix/master[2182]: daemon started -- version 2.10.1, configuration /etc/postfix
Jan 15 10:00:45 mail systemd[1]: Started Postfix Mail Transport Agent.
Hint: Some lines were ellipsized, use -l to show in full.
2、 配置/etc/postfix/main.cf(注意每次配置完需重啓服務才能生效,新手易犯問題)
vim /etc/postfix/main.cf
# 修改內容:
# 75行: 取消註釋,設置hostname 郵局系統的主機名
myhostname = mail.abc.com
# 83行: 取消註釋,設置域名 郵局系統的域名
mydomain = abc.com
# 99行: 取消註釋 從本機發出郵件的域名名稱
myorigin = $mydomain
# 116行: 默認是localhost,我們需要修改成all 監聽的網卡接口
inet_interfaces = all
# 119行: 推薦ipv4,如果支持ipv6,則可以爲all
inet_protocols = ipv4
# 164行: 添加 可接收郵件的主機名或域名
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
# 264行: 取消註釋,指定內網和本地的IP地址範圍 設置可轉發哪些主機的郵件
mynetworks = 127.0.0.0/8
# 419行: 取消註釋,郵件保存目錄
home_mailbox = Maildir/
# 571行: 添加
smtpd_banner = $myhostname ESMTP
# 添加到最後
# 規定郵件最大尺寸爲10M
message_size_limit = 10485760
# 規定收件箱最大容量爲1G
mailbox_size_limit = 1073741824
# SMTP認證
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks,permit_auth_destination,permit_sasl_authenticated,reject
- 檢查語法錯誤(與named-check用法一樣)
postfix check
- 查看postfix的非默認並已生效配置
[root@mail ~]# postconf -n
alias_database = hash:/etc/aliases
alias_maps = hash:/etc/aliases
command_directory = /usr/sbin
config_directory = /etc/postfix
daemon_directory = /usr/libexec/postfix
data_directory = /var/lib/postfix
debug_peer_level = 2
debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5
home_mailbox = Maildir/
html_directory = no
inet_protocols = all
mail_owner = postfix
mailq_path = /usr/bin/mailq.postfix
manpage_directory = /usr/share/man
mydestination = $myhostname, $mydomain
mydomain = auto.com
myhostname = mail.auto.com
mynetworks = 127.0.0.1
myorigin = $mydomain
newaliases_path = /usr/bin/newaliases.postfix
queue_directory = /var/spool/postfix
readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES
sample_directory = /usr/share/doc/postfix-2.10.1/samples
sendmail_path = /usr/sbin/sendmail.postfix
setgid_group = postdrop
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
unknown_local_recipient_reject_code = 550
3、驗證測試
- 添加電子郵箱賬號
-------------增加郵件測試帳號--------------
[root@mail ~]# groupadd mailusers //創建組給測試帳號
[root@mail ~]# useradd -g mailusers -s /sbin/nologin user01 // 創建user01帳戶只屬於mailusers組並不能登錄系統,用於測試郵件
[root@mail ~]# passwd user01 //創建user01密碼,使用test1234
[root@mail ~]# useradd -g mailusers -s /sbin/nologin user02
[root@mail ~]# passwd user02
- 使用 telnet 測試發信(user01給user02)
[root@mail ~]# telnet mail.auto.com 25 // 連接郵件服務器的25端口
Trying 127.0.0.1...
Connected to mail.auto.com.
Escape character is '^]'.
220 mail.auto.com ESMTP Postfix
helo localhost // 宣告客戶端的主機地址
250 mail.auto.com
mail from:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
250 2.1.5 Ok
data // 表示要開始寫郵件內容了
354 End data with <CR><LF>.<CR><LF>
Subject: my test mail 1. // 指定郵件標題
my first mial document...
.
250 2.0.0 Ok: queued as 2D37565968E
quit // 斷開telnet連接
221 2.0.0 Bye
Connection closed by foreign host.
- 驗證收件
[root@mail ~]# ls /home/user02/Maildir/new/
1579055447.V803Ie5d1f4M449562.mail
[root@mail ~]# cat /home/user02/Maildir/new/1579055447.V803Ie5d1f4M449562.mail
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Received: from localhost (localhost [127.0.0.1])
by mail.auto.com (Postfix) with SMTP id 2D37565968E
for <[email protected]>; Wed, 15 Jan 2020 10:30:01 +0800 (CST)
Subject: my test mail 1.
my first mial document...
Message-Id: <[email protected]>
Date: Wed, 15 Jan 2020 10:30:01 +0800 (CST)
From: [email protected]
Linux-Postfix+Dovecot+Postfixadmin+Roundcubemail 搭建郵件服務器管理系統(三)