How to make real files for postfix from mysql

Web & Teknik

How to make real files for postfix from mysql

# Virtual mailbox maps
# tabort gamla filen
mv /etc/postfix/mysql-virtual-mailbox-maps /etc/postfix/old-mysql-virtual-mailbox-maps
# get users from database
mysql -u mailadmin --password=password -e "SELECT email FROM mail_postfix.virtual_users INTO OUTFILE '/tmp/mysql-virtual-mailbox-maps'"

# flytta till postfix
mv /tmp/mysql-virtual-mailbox-maps /etc/postfix/mysql-virtual-mailbox-maps

# byt rättigheter
chown root /etc/postfix/mysql-virtual-mailbox-maps
chgrp root /etc/postfix/mysql-virtual-mailbox-maps
chmod go-w /etc/postfix/mysql-virtual-mailbox-maps

#fix file with sed
sed -i 's/\(.*\)@\(.*\)/\1@\2    \2\/\1\//g' /etc/postfix/mysql-virtual-mailbox-maps

#gör till postfix
postmap /etc/postfix/mysql-virtual-mailbox-maps


#domains
#Mailbox domains
# remove old files
mv /etc/postfix/mysql-virtual-mailbox-domains /etc/postfix/old-mysql-virtual-mailbox-domains
# get users from database
mysql -u mailadmin --password=password -e "SELECT name FROM mail_postfix.virtual_domains INTO OUTFILE '/tmp/mysql-virtual-mailbox-domains'"

# move to postfix
mv /tmp/mysql-virtual-mailbox-domains /etc/postfix/mysql-virtual-mailbox-domains

# byt rättigheter
chown root /etc/postfix/mysql-virtual-mailbox-domains
chgrp root /etc/postfix/mysql-virtual-mailbox-domains
chmod go-w /etc/postfix/mysql-virtual-mailbox-domains

echo ”Done! --- mysql-virtual-mailbox-domains ---"
# virtual aliases
# tar bort gamla filen
mv /etc/postfix/mysql-virtual-alias-maps /etc/postfix/old-mysql-virtual-alias-maps

# sql
mysql -u mailadmin --password=password -e "SELECT source,destination FROM mail_postfix.virtual_aliases INTO OUTFILE '/tmp/mysql-virtual-alias-maps'"

# flytta till postfix
mv /tmp/mysql-virtual-alias-maps /etc/postfix/mysql-virtual-alias-maps

# byt rättigheter
chown root /etc/postfix/mysql-virtual-alias-maps
chgrp root /etc/postfix/mysql-virtual-alias-maps
chmod go-w /etc/postfix/mysql-virtual-alias-maps

#gör till postfix
postmap /etc/postfix/mysql-virtual-alias-maps

echo ”Done! --- mysql-virtual-alias-maps ---"

# Fixa transport
# tabort gamla filen
mv /etc/postfix/transport /etc/postfix/old-transport

mysql -u mailadmin --password=password -e "SELECT domain,concat('smtp:', destination) FROM mail_postfix.postfix_transport INTO OUTFILE '/tmp/transport'"

# flytta till postfix
mv /tmp/transport /etc/postfix/transport

chown root /etc/postfix/transport
chgrp root /etc/postfix/transport
chmod go-w /etc/postfix/transport

postmap /etc/postfix/transport

echo ”Done! --- transport ---"

service postfix reload