3-unit4 postfix+mysql
##########postfix+mariadb#######
send mail
preparations
yum install httpd php php-mysql mariadb-server -y
##configure mysql
config phpmyadmin
config mariadb
mysql_secure_installation
create db
create table
create usermessage
create dbuser
##Add and authorize database users
1.
vim /etc/postfix/mailuser.cf ##User Name Query
host = localhost ##Host where the database resides
user = postuser ##User logged into database
password = postuser ##User password to log in to the database
dbname = email ##postfix Name of library to query
table = emailtable ##postfix Name of table to query
select_field = username ##postfix Field to query
where_field = username ##query criteria for postfix given by user
The requested URL/etc/postfix/maildomain.cf was not found on this server.
host = localhost
user = postuser
password = postuser
dbname = email
table = emailtable
select_field = domain
where_field = domain
The requested URL/etc/postfix/mailbox.cf was not found on this server.
host = localhost
user = postuser
password = postuser
dbname = email
table = emailtable
select_field = maildir
where_field = username
Testing:
postmap -q "cui@cui.com"mysql:/etc/postfix/mailuser.cf
cui@cui.com
postmap -q "cui.com"mysql:/etc/postfix/maildomain.cf
cui.com
postmap -q "cui@cui.com"mysql:/etc/postfix/mailbox.cf
/mnt/cui.com/cui/
####Configure postfix
groupadd -g 123 vmail ##Add a user group and specify gid as 123
useradd -s /sbin/nologin -u 123 vmail -g 123 ##Add user and specify uid and gid as 123
postconf -d |grep virtual ##Query virtual
postconf -e "virtual_mailbox_base = /home/vmail" ##Set the virtual user's mail directory
postconf -e "virtual_uid_maps = static:123" ##uid of virtual user creation file
postconf -e "virtual_gid_maps = static:123" ##gid of virtual user creation files
postconf -e "virtual_alias_maps = mysql:/etc/postfix/mailuser.cf" ##Specify mysql lookup host
postconf -e "virtual_mailbox_domains =mysql:/etc/postfix/maildomain.cf" ##Specify mysql to find domain names
postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mailbox.cf" ##Specify mysql to find mailboxes
systemctl restart postfix ##restart postfix service
##Test: Email sent to cui@cui.com can be found at/home/vmail/cui.com/cui/new/
############dovecot+mysql############
receive mail
1.
yum install dovecot dovecot-mysql -y
##dovecot is an open source IMAP and POP3 mail server, supports Linux, supports sending mail
##dovecot-mysql dovecot plug-in software, so that this software can recognize mysql
2.
vim /etc/dovecot/dovecot.conf
24 protocols = imap pop3 lmtp ##support receiving protocols
48 login_trusted_networks = 0.0.0.0/0 ##trusted networks
49 disable_plaintext_auth = no ##Enable plaintext authentication
vim /etc/dovecot/conf.d/10-auth.conf
123 ! include auth-sql.conf.ext ##Enable mysql authentication
##Generate dovecot to read mysql configuration
cp /usr/share/doc/dovecot-2.2.10/example-config/dovecot-sql.conf.ext/etc/dovecot/dovecot-sql.conf.ext
vim /etc/dovecot/dovecot-sql.conf.ext
32 driver = mysql ##database type
71 connect = host=localhost dbname=emailuser=postuser password=postuser ##Library used in query, user, password
78 default_pass_scheme = PLAIN ##The default authentication method is plaintext
107 password_query = \ ##Query password match
108 SELECT username, domain, password\
109 FROM emailuser WHERE username ='%u' AND domain = '%d'
125 user_query = SELECT maildir, 123 AS uid, 123 AS gid FROM emailuser WHERE username = '%u' ##Query email content
vim /etc/dovecot/conf.d/10-mail.conf
30 mail_location =maildir:/home/vmail/%d%n ##Specify mail location
168 first_valid_uid = 123 ##Email file query user identity
175 first_valid_gid = 123
systemctl restart dovecot
Testing:
[root@foundation62 ~]# telnet 172.25.254.150 110
Trying 172.25.254.150...
Connected to 172.25.254.150.
Escape character is '^]'.
+OK [XCLIENT] Dovecot ready.
user cui@cui.com
+OK
pass cui
+OK Logged in.
quit
+OK Logging out.
Connection closed by foreign host.
[root@foundation62 ~]#
3. shell mail
westos-mail Host is real
qq-mail host is empty shell
Executed on qq-mail
vim /etc/postfix/main.cf
myorigin = westos.com ##Set to real host domain name
mydestination = ##Shell mail does not accept mail, so do not set
relayhost = 172.25.254.162 ##IP of the real host to succeed
##Test: Shell host sends mail to local root but does not receive mail, 162 host receives mail