Set up email service in CentOS
Cyrus-sasl account authentication (local)
Send email with postfix
Receive email from dovecot
I. System configuration
All account emails are stored in the system/data/% U Directory
Modify the user template and add a new user to automatically create a Mail directory to store Mail files
Domain: mxt.selboo.com.cn MX record mail.mxt.selboo.com.cn
Create a user email directory under the user template
This is The Code
[Root @ selboo ~] # Mkdir/etc/skel/Mail
[Root @ selboo ~] # Chmod 700/etc/skel/Mail
Parsed in 0.000 seconds at N/
Create an "m1" email account
This is The Code
[Root @ selboo ~] # Useradd-s/sbin/nologin-d/data/m1 m1
Parsed in 0.000 seconds at N/
Change "m1" password to '123'
This is The Code
[Root @ selboo ~] # Echo '000000' | passwd -- stdin m1
Changing password for user m1.
Passwd: all authentication tokens updated successfully.
Parsed in 0.000 seconds at N/
Install software
This is The Code
[Root @ selboo ~] # Yum install postfix cyrus-sasl * dovecot
Parsed in 0.000 seconds at N/
II. cyrus-sasl configuration
1. Modify the/etc/sysconfig/saslauthd file for local authentication.
This is The Code
Cat/etc/sysconfig/saslauthd | grep-v '^ #'
SOCKETDIR =/var/run/saslauthd
MECH = shadow
Parsed in 0.000 seconds at N/
2. Modify smtpd. conf.
This is The Code
[Root @ selboo ~] # Cat/etc/sasl2/smtpd. conf
Pwcheck_method: saslauthd
Mech_list: plain login
Parsed in 0.000 seconds at N/
3. Verify that sasl is normal
This is The Code
[Root @ selboo ~] # Testsaslauthd-u m1-p 12345567
0: OK "Success ."
Parsed in 0.000 seconds at N/
3. Postfix configuration
Main. cf configuration file
This is The Code
Cat/etc/postfix/main. cf | grep-v '^ #'
Queue_directory =/var/spool/postfix
Command_directory =/usr/sbin
Daemon_directory =/usr/libexec/postfix
Data_directory =/var/lib/postfix
Mail_owner = postfix
Myhostname = mail.mxt.selboo.com.cn
Mydomain = mxt.selboo.com.cn
Myorigin = $ myhostname
Inet_interfaces = all
Mydestination = $ myhostname, localhost. $ mydomain, localhost, $ mydomain, mail. $ mydomain, www. $ mydomain, ftp. $ mydomain
Unknown_local_recipient_reject_code = 550
Mynetworks_style = subnet
Mynetworks = 127.0.0.1
Relay_domains = $ mydestination
Alias_maps = hash:/etc/aliases
Alias_database = hash:/etc/aliases
Home_mailbox = Mail/
Debug_peer_level = 2
Sendmail_path =/usr/sbin/sendmail. postfix
Newaliases_path =/usr/bin/newaliases. postfix
Mailq_path =/usr/bin/mailq. postfix
Setgid_group = postdrop
Html_directory = no
Manpage_directory =/usr/share/man
Sample_directory =/usr/share/doc/postfixed-2.6.6/samples
Readme_directory =/usr/share/doc/postfix-2.6.6/README_FILES
# Sasl authentication
Smtpd_sasl_auth_enable = yes
Smtpd_sasl_security_options = noanonymous
Broken_sasl_auth_clients = yes
Smtpd_recipient_restrictions = permit_sasl_authenticated, reject_unauth_destination, permit_mynetworks
Smtpd_client_restrictions = permit_sasl_authenticated
Parsed in 0.000 seconds at N/
4. dovecot configuration
1. Modify the/etc/dovecot. conf file.
This is The Code
[Root @ selboo ~] # Cat/etc/dovecot. conf | grep-E "protocols | listen ="
Protocols = pop3
Listen = *
Parsed in 0.000 seconds at N/
Only enable POP3 and only listen for IPV4 addresses
2. Disable the POP3S protocol.
This is The Code
[Root @ selboo ~] # Cat/etc/dovecot/conf. d/10-ssl.conf | grep "ssl ="
Ssl = no
Parsed in 0.000 seconds at N/
3. Specify the Mail directory
This is The Code
[Root @ selboo ~] # Cat 10-mail.conf | grep "mail_location = maildir"
Mail_location = maildir :~ /Mail
Parsed in 0.000 seconds at N/
4. Modify the auto file
This is The Code
[Root @ selboo ~] # Cat 10-auth.conf | grep disable_plaintext_auth
Disable_plaintext_auth = no
Parsed in 0.000 seconds at N/
No, Error 1 will occur during Email receiving.
V. Error Records
1. Error 1
/Var/log/maillog file
Dovecot: pop3-login: Disconnected (tried to use disabled plaintext auth)
2. Error 2
/Var/log/maillog file
Initialization failed: mail_location not set and autodetection failed: Mail storage autodetection fa
Solution 2
/Etc/dovecot/conf. d/10-mail.conf
Mail_location = maildir :~ /Mail
Set up email service in CentOS-virtual domain
Add a virtual domain to the Postfix this time.
Domain address MX record system directory (% U user main directory)
Mxt.selboo.com.cn m1@mxt.selboo.com.cn mail.mxt.selboo.com.cn/data/% U
Mxy.selboo.com.cn m2@mxy.selboo.com.cn mail.mxy.selboo.com.cn/mxy/% U
1. Add a user
This is The Bash Code
Useradd-d/data/m1 m1-s/sbin/nologin
Useradd-d/mxy/MB 2 m2-s/sbin/nologin
Change password
Echo '200' | passwd -- stdin m1
Echo '200' | passwd -- stdin m2
Get id
Id m1
Uid = 513 (m1) gid = 513 (m1) groups = 513 (m1)
Id m2
Uid = 514 (m2) gid = 514 (m2) groups = 514 (m2)
Parsed in 0.019 seconds at 13.30 KB/s
2. Configure Postfix
Modify main. cf to add the following parameters
This is The Code
Virtual_alias_maps = hash:/etc/postfix/virtual_alias_maps
Virtual_mailbox_domains =/etc/postfix/virtual_mailbox_domains
Virtual_mailbox_maps = hash:/etc/postfix/virtual_mailbox_maps
Virtual_uid_maps = hash:/etc/postfix/virtual_uids
Virtual_gid_maps = hash:/etc/postfix/virtual_gids
Virtual_mailbox_base =/
Virtual_maildir_extended = yes
Virtual_create_maildirsize = yes
Parsed in 0.000 seconds at N/
Virtual_alias_maps forwarding configuration
Virtual_mailbox_domains domain configuration
Virtual_mailbox_maps user directory configuration
Virtual_uid_maps UID
Virtual_gid_maps GID
This is The Code
Cat/etc/postfix/virtual_alias_maps
M1@mxt.selboo.com.cn, m1@mxt.selboo.com.cn
Cat/etc/postfix/virtual_mailbox_domains
Mxt.selboo.com.cn
Mxy.selboo.com.cn
Cat/etc/postfix/virtual_mailbox_maps
M1@mxt.selboo.com.cn, data, m1, Mail/
M2@mxy.selboo.com.cn/mxy/m2/Mail/
Cat virtual_uids
M1@mxt.selboo.com.cn 513
M1@mxt.selboo.com.cn 514
Cat virtual_gids
M1@mxt.selboo.com.cn 513
M1@mxt.selboo.com.cn 514
Postmap/etc/postfix/virtual_alias_maps
Postmap/etc/postfix/virtual_mailbox_maps
Postmap/etc/postfix/virtual_uids
Postmap/etc/postfix/virtual_gids
Parsed in 0.000 seconds at N/
Troubleshooting records
I./var/log/maillog file
Fatal: bad string length 0 <1: virtual_mailbox_base =
Add virtual_mailbox_base =/parameter
II./var/log/maillog file
Warning: do not list domain mxt.selboo.com.cn in BOTH mydestination and virtual_mailbox_domains
The mydomain parameter and virtual_mailbox_domains are repeated.
PS: because it depends on local system users, the two domains cannot have the same account