postfix+dns+dovecot+openwebmail

一:搭建DNS服務器
二:搭建postfix服務器及普通發信
三:普通收信
四:認證收信
五:squirrelmail收發郵件(搭建網頁收發郵件)

dns 搭建:查考我的另一個博客https://blog.csdn.net/qq_37699336/article/details/80180853

第二部分:搭建postfix並配置基本發信功能
[root@localhost ~]# postconf –a //驗證是否支持cyrus dovecot功能
這裏寫圖片描述
(若postfix已安裝好,則會支持這兩個功能,若不支持,表示postfix未安裝好;CentOS 7開始默認系統自帶postfix。)
------------編輯主配置文件--------------
[root@localhost ~]# vi /etc/postfix/main.cf
myhostname = mail.cyl.cn //郵件服務器的主機名
mydomain = cyl.cn //郵件域
myorigin = $mydomain //往外發郵件的郵件域
inet_interfaces = 192.168.0.2, 127.0.0.1 //監聽的網卡 (注意,兩個地址之間有空格)
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
home_mailbox = Maildir/ //郵件存放的目錄

保存退出
[root@localhost ~]# postfix check //檢查語法錯誤(與named-check用法一樣)更改默認MTA爲Postfix:
/usr/sbin/alternatives --set mta /usr/sbin/sendmail.postfix
完事兒,再次檢查下是否將MTA改爲Postfix了:
alternatives --display mta
[root@localhost ~]# systemctl restart postfix //重啓服務
[root@localhost ~]# postconf –n //查看postfix的非默認並已生效配置
-------------增加郵件測試帳號--------------
[root@localhost ~]# groupadd mailusers //創建組給測試帳號
[root@localhost ~]# useradd -g mailusers -s /sbin/nologin jack
//創建jack帳戶只屬於mailusers組並不能登錄系統,用於測試郵件
[root@localhost ~]# passwd jack //創建jack密碼
[root@localhost ~]# useradd -g mailusers -s /sbin/nologin tom
[root@localhost ~]# passwd tom
--------------連接服務器的25端口進行簡單發信測試-----------
[root@localhost ~]# telnet mail.cyl.cn 25
//連接成功,開始寫信
helo mail.cyl.cn //聲明本機的主機
mail from:[email protected] //聲明發件人地址
rcpt to:[email protected] //聲明收件人地址
data //寫正文
i am jack!!
. //正文結束標記
quit // 退出
這裏寫圖片描述

cd /home/tom/Maildir/new/
ls 查看對i應的文件

方法二:搭建dovecot提供收信服務
--------------安裝dovecot軟件----------------
[root@localhost ~]# yum install -y dovecot
---------------編輯配置文件--------------
[root@localhost ~]# vi /etc/dovecot/dovecot.conf //如果有去掉註釋沒有加上
protocols = imap pop3 lmtp
listen = , :: //後邊的 :: 代表的是ipv6
!include conf.d/
.conf
!include conf.d/10-auth.conf
在最後加上
ssl = no
disable_plaintext_auth = no
mail_location = maildir:~/Maildir
----------------啓動服務--------------
[root@localhost ~]# systemctl start dovecot
[root@localhost ~]# netstat -anpt | grep dovecot
tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 53455/doveco
tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN 53455/doveco
tcp6 0 0 :::110 ::😗 LISTEN 53455/doveco
tcp6 0 0 :::143 ::😗 LISTEN 53455/doveco

//110,143端口需要監聽

---------------收信驗證---------------
[root@localhost ~]# telnet mail.aa.com 110
user tom //收件人登錄
pass 123 //郵箱密碼
list //列表查看郵件
retr 1 //讀取編號爲1的郵件
quit //退出郵箱

vi /etc/postfix/main.cf
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 0.0.0.0/0 //允許接收所有網段發來的郵件,根據情況自行修改
relay_domains =$mydestination
在最後增加
smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
default_process_limit = 50
default_destination_concurrency_limit = 20
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_sasl_application_name = smtpd
broken_sasl_auth_clients = yes
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
smtpd_client_restrictions = permit_sasl_authenticated
保存退出
service postfix restart

安裝cyrus-sasl

# yum -y install cyrus-sasl
chkconfig saslauthd on

vi /etc/sysconfig/saslauthd
修改 /etc/sysconfig/saslauthd
# vim /etc/sysconfig/saslauthd
# Directory in which to place saslauthd’s listening socket, pid file, and so
# on. This directory must already exist.
SOCKETDIR=/var/run/saslauthd
# Mechanism to use when checking passwords. Run “saslauthd -v” to get a list
# of which mechanism your installation was compiled with the ablity to use.
MECH=shadow

修改 vi /etc/sasl2/smtpd.conf

pwcheck_method: saslauthd

mech_list: plain login
測試 saslauthd
# service saslauthd restart
# testsaslauthd -u tom -p ‘tom’
0: OK “Success.”

openwebmail安裝
# cd /etc/yum.repos.d
# wget -q http://openwebmail.org/openwebmail/download/redhat/rpm/release/openwebmail.repo
centos7安裝openwebmail (yum install -y openwebmail 是centos6.5中的)
FUCK,FUCK,FUCK,搞了(4個小時,操了個dj),頭髮掉了一半
cd /opt
centos7中需要perl 和perl-suidperl 而且要配套
perl
wget http://mirror.centos.org/centos/7/os/x86_64/Packages/perl-5.16.3-292.el7.x86_64.rpm
rpm -ivh --force --nodeps perl-5.16.3-292.el7.x86_64.rpm

perl-suidperl
wget http://mirror.centos.org/centos/6/os/x86_64/Packages/perl-suidperl-5.10.1-144.el6.x86_64.rpm
rpm -ivh --force --nodeps perl-suidperl-5.10.1-144.el6.x86_64.rpm
配置openwebmail

# vi /var/www/cgi-bin/openwebmail/etc/openwebmail.conf

domainnames cyl.cn
default_language zh_CN.GB2312
default_timeoffset +0800
default_iconset Cool3D.Chinese.Simplified
auth_module auth_unix.pl
mailspooldir /var/spool/mail
ow_cgidir /var/www/cgi-bin/openwebmail
ow_cgiurl /cgi-bin/openwebmail
ow_htmldir /var/www/data/openwebmail
ow_htmlurl /data/openwebmail
logfile /var/log/openwebmail.log

#vi /var/www/cgi-bin/openwebmail/etc/defaults/openwebmail.conf
domainnames cyl
smtpserver 192.168.0.2
#smtpserver 127.0.0.1 (這個如果是再阿里雲上的話因爲是自己對自己的測試,所以用127.0.0.1而不是用外網地址39.107.116.193)
authpop3_server 192.168.0.2
#authpop3_server 192.168.0.2 (這個如果是再阿里雲上的話因爲是自己對自己的測試,所以用127.0.0.1而不是用外網地址39.107.116.193)
smtpport 25
smtpauth no

# cd /var/www/cgi-bin/openwebmail
yum install -y libperl*
yum install perl-Socket -y
yum install perl-Digest -y
yum install perl-Digest-MD5
yum install perl-Text-Iconv.x86_64
/唯一能說的就是慢慢找錯吧 -----------------------兩天才弄好所有錯
# ./openwebmail-tool.pl --init
perl-suidperl-5.8.8 (通過CentOS的yum功能直接安裝,安裝版本 5.8.8這個是和perl配套的,如果和perl版本不一致可能導致初始化openwebmail時找不到libperl.so,openwebmail的輔助軟件,必須要有);
#service httpd restart

打開瀏覽器

輸入192.168.45.128/webmail (或者 mail.test.com/webmail,這個我只在128本機上通過,猜測其他機子連接應該修改其dns)
系統提示:
‘/var/www/cgi-bin/openwebmail/.openwebmail.pl’ must setuid to root

原來剛纔執行perl /var/www/cgi-bin/openwebmail/misc/tools/wrapsuid/wrapsuid.pl /var/www/cgi-bin/openwebmail/後,所有openwebmail*.pl文件的s位沒有了。所以
chmod 4755 /var/www/cgi-bin/openwebmail/openwebmail*.pl
訪問: http://localhost/cgi-bin/openwebmail/openwebmail.pl
OK,可以看到登陸框了,說明openwebmail已經安裝成功了,下面就是來結合sendmail了。
這裏寫圖片描述
這裏寫圖片描述
這裏寫圖片描述

這裏寫圖片描述

收信的時候
這裏寫圖片描述

這裏寫圖片描述

這裏寫圖片描述
可能出現問題:

如果出現了下面的問題 Couldn’t create File /var/log/openwebmail.log! (Permission denied)

在網上找到解決辦法了:如下方面 運行:

#touch /var/log/openwebmail.log

#chcon -u system_u /var/log/openwebmail.log
#chcon -t httpd_sys_script_rw_t /var/log/openwebmail.log

#chcon -t httpd_unconfined_script_exec_t /var/www/cgi-bin/openwebmail/openwebmail*

我還遇到了一個問題,記不清了。大概是不能在/var/spool下面創建mai文件夾,解決方法是用root權限自己建立一個

全文借鑑網站
https://blog.csdn.net/kirao/article/details/3519683
中間遇到的
Requires: perl-suidperl
Removing: 3:perl-suidperl-5.8.1-92.i386 (installed)
perl-suidperl = 3:5.8.1-92
Obsoleted By: 4:perl-5.16.3-292.el7.x86_64 (base)

rpm包
強制卸載:rpm -e –nodeps xxxxxx.rpm

強制安裝:rpm -ivh –nodeps xxxxxx.rpm

openwebmail的配置
http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed19fa950d100b92235c438014628c8c52358fc51984642c101a39fec57c7e574ecec57e6402b8492ae8f72b73300820b58cc8ff109be4866d72c8713b2e47da0658c418dfdc3021d656924de8df0e97bde74395b9d2a28216049616522adfa3d004&p=c639d41086cc42ad589fc7710f488d&newp=cb759a46d4c308e90be296365b51bb231610db2151d6d0116b82c825d7331b001c3bbfb423251407d6c67d600aa84356effb35703d0923a3dda5c91d9fb4c57479c161&user=baidu&fm=sc&query=linux%D6%D0%B5%C4+openwebmail&qid=c24970630001f5a8&p1=3

找錯最好文章
https://www.cnblogs.com/wwufengg/articles/openwebmail-error.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章