sudo apt-get install mysql-client mysql-serversudo apt-get install phpmyadmin apache2 libapache2-mod-php5 php5 php5-mysqlsudo apt-get install postfix postfix-mysql postfix-doc courier-authdaemon courier-authlib-mysql courier-pop courier-pop-ssl courier-imap courier-imap-ssl postfix-tls libsasl2-2 libsasl2-modules libsasl2-modules-sql sasl2-bin libpam-mysql openssl#開始建 postfix to mysql的連結
sudo vim /etc/postfix/mysql_virtual_alias_maps.cf#################################user = mysql_usernamepassword = mysql_pass
#在 main.conf 中加入建立連結的選 項hosts = 127.0.0.1dbname = mysql_dbnametable = aliasselect_field = gotowhere_field = address#################################sudo vim /etc/postfix/mysql_virtual_domains_maps.cf#################################user = mysql_usernamepassword = mysql_passhosts = 127.0.0.1dbname = mysql_dbnametable = domainselect_field = domainwhere_field = domain#additional_conditions = and backupmx = '0' and active = '1'#################################sudo vim /etc/postfix/mysql_virtual_mailbox_maps.cf#################################user = mysql_usernamepassword = mysql_passhosts = 127.0.0.1dbname = mysql_dbnametable = mailboxselect_field = maildirwhere_field = username#additional_conditions = and active = '1'#################################sudo vim /etc/postfix/mysql_virtual_mailbox_limit_maps.cf#################################user = mysql_usernamepassword = mysql_passhosts = 127.0.0.1dbname = mysql_dbnametable = mailboxselect_field = quotawhere_field = username#additional_conditions = and active = '1'#################################sudo vim /etc/postfix/mysql_relay_domains_maps.cf#################################user = mysql_usernamepassword = mysql_passhosts = 127.0.0.1dbname = mysql_dbnametable = domainselect_field = domainwhere_field = domainadditional_conditions = and backupmx = '1'#################################sudo chgrp postfix /etc/postfix/mysql_*.cfsudo chmod 640 /etc/postfix/mysql_*.cf
sudo vim /etc/postfix/main.cf
#################################
# Virtual Mailbox Domain Settings
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_mailbox_limit = 51200000
virtual_minimum_uid = 5000
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
virtual_mailbox_base = /home/vmail
virtual_transport = virtual
# Additional for quota support
virtual_create_maildirsize = yes
virtual_mailbox_extended = yes
virtual_mailbox_limit_maps = mysql:/etc/postfix/mysql_virtual_mailbox_limit_maps.cf
virtual_mailbox_limit_override = yes
virtual_maildir_limit_message = Sorry, the your maildir has overdrawn your diskspace quota, please free up some of spaces of your mailbox try again.
virtual_overquota_bounce = yes
#################################
### 改nameserversudo groupadd -g 5000 vmailsudo useradd -m -g vmail -u 5000 -d /home/vmail -s /bin/bash vmail
sudo vim /var/spool/postfix/etc/resolv.conf
#設定
nameserver 168.95.1.1
nameserver 8.8.8.8
##沒設定寄出的信會就出現Host or domain name not found. Name service error ,nameserver 可指定自家的不一定要用168.95.1.1
### smtp登入的使用者驗證
vi /etc/courier/authdaemonrc## Change to mysql modeauthmodulelist="authmysql"## 顯示 login 的 log 來 debugDEBUG_LOGIN=2sudo vim /etc/courier/authmysqlrc#################################MYSQL_SERVER 127.0.0.1MYSQL_USERNAME mysql_usernameMYSQL_PASSWORD mysql_passMYSQL_DATABASE mysql_dbnameMYSQL_USER_TABLE mailboxMYSQL_LOGIN_FIELD usernameMYSQL_NAME_FIELD nameMYSQL_CRYPT_PWFIELD password#MYSQL_CLEAR_PWFIELD passwordMYSQL_MAILDIR_FIELD maildirMYSQL_QUOTA_FIELD concat(quota,'S')MYSQL_HOME_FIELD '/home/vmail'MYSQL_UID_FIELD '5000'MYSQL_GID_FIELD '5000'#################################/etc/postfix/sasl/smtpd.conf不用這個#################################pwcheck_method: auxpropauxprop_plugin: sqlmech_list: plain login cram-md5 digest-md5sql_engine: mysqlsql_hostnames: 127.0.0.1sql_user: mysql_usernamesql_passwd: mysql_passsql_database: mysql_dbnamesql_select: select password from mailbox where username='%u@%r' and active = 1#################################改這個##########################pwcheck_method: saslauthdmech_list: plain loginallow_plaintext: trueauxprop_plugin: mysqlsql_hostnames: 127.0.0.1sql_user: mysql_usernamesql_passwd: mysql_passsql_database: mysql_dbnamesql_select: select password from mailbox where username='%u@%r' and active = 1##########################sudo vim /etc/pam.d/smtp##########################auth required pam_mysql.so user=mysql_username passwd=mysql_pass host=127.0.0.1 db=mysql_dbname table=mailbox usercolumn=username passwdcolumn=password crypt=1account sufficient pam_mysql.so user=mysql_username passwd=mysql_pass host=127.0.0.1 db=mysql_dbname table=mailbox usercolumn=username passwdcolumn=password crypt=1##########################
### 加入 smtp 的驗証
sudo vim /etc/postfix/main.cf##########################smtpd_recipient_restrictions = reject_unauth_pipelining, permit_mynetworks, permit_sasl_authenticated, reject_non_fqdn_recipient, reject_unknown_recipient_domain reject_unauth_destination, permit# modify the existing smtpd_sender_restrictionssmtpd_sender_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_non_fqdn_sender, reject_unknown_sender_domain, reject_unauth_pipelining, permit# then add thesesmtpd_sasl_auth_enable = yesbroken_sasl_auth_clients = yessmtpd_sasl_security_options = noanonymoussmtpd_sasl_local_domain =##########################
### 建立 key
sudo openssl req -new -outform PEM -out /etc/postfix/smtpd.cert -newkey rsa:2048 -nodes -keyout /etc/postfix/smtpd.key -keyform PEM -days 3650 -x509sudo chmod 640 /etc/postfix/smtpd.key
### 啟用 saslauthd
sudo adduser postfix sasl
sudo mkdir -p /var/spool/postfix/var/run/saslauthd
### 編輯 /etc/default/saslauthd
sudo vim /etc/default/saslauthd
######只改
START=yes
OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd -r"
############
參考來源:http://www.debiantutorials.com/installing-postfix-with-mysql-backend-and-sasl-for-smtp-authentication/sudo /etc/init.d/saslauthd restart
沒有留言:
張貼留言