אנדרואיד

התקן וקבע את התצורה של Postfix ו- dovecot

9. Настройка MAIL (postfix, dovecot)

9. Настройка MAIL (postfix, dovecot)

תוכן עניינים:

Anonim

זהו הפוסט השני של הגדרת וסדרת שרתי הדואר שלנו. בפוסט זה נראה לך כיצד להתקין ולהגדיר את Postfix ו- Dovecot, שני המרכיבים העיקריים של מערכת הדואר שלנו.

Postfix הוא סוכן העברת דואר בקוד פתוח (MTA), שירות המשמש לשליחה וקבלת דוא"ל. Dovecot הוא שרת IMAP / POP3 ובהתקנה שלנו הוא יטפל גם במסירה מקומית ובאימות משתמשים.

מדריך זה נכתב עבור אובונטו 16.04, אולם אותם צעדים עם שינויים קטנים צריכים לעבוד על כל גרסה חדשה יותר של אובונטו.

תנאים מוקדמים

לפני שתמשיך במדריך זה, וודא שאתה מחובר כמשתמש עם הרשאות סודו.

התקן את Postfix ו- Dovecot

חבילות Dovecot במאגרי ברירת המחדל של אובונטו מיושנות. על מנת לנצל את מודול imap_sieve אנו imap_sieve את Dovecot ממאגר הקהילה של Dovecot.

הוסף את מפתח ה- GPG למאגר למפתח המקור המתאים שלך עם הפקודה הבאה של wget:

wget -O- https://repo.dovecot.org/DOVECOT-REPO-GPG | sudo apt-key add -

אפשר את מאגר הקהילה של Dovecot באמצעות הפקודה הבאה:

echo "deb https://repo.dovecot.org/ce-2.3-latest/ubuntu/$(lsb_release -cs) $(lsb_release -cs) main" | sudo tee -a /etc/apt/sources.list.d/dovecot.list

sudo apt update sudo debconf-set-selections <<< "postfix postfix/mailname string $(hostname -f)" sudo debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'" sudo apt install postfix postfix-mysql dovecot-imapd dovecot-lmtpd dovecot-pop3d dovecot-mysql

תצורת Postfix

אנו נקבע את Postfix לשימוש בתיבות דואר וירטואליות.

התחל ביצירת קבצי התצורה של sql אשר ינחו את התיקון לאחר הגישה לגישה למסד הנתונים של MySQL, שנוצר בחלק הראשון של הסדרה.

sudo mkdir -p /etc/postfix/sql

פתח את עורך הטקסט שלך וצור את הקבצים הבאים:

/etc/postfix/sql/mysql_virtual_domains_maps.cf

user = postfixadmin password = P4ssvv0rD hosts = 127.0.0.1 dbname = postfixadmin query = SELECT domain FROM domain WHERE domain='%s' AND active = '1' /etc/postfix/sql/mysql_virtual_alias_maps.cf

user = postfixadmin password = P4ssvv0rD hosts = 127.0.0.1 dbname = postfixadmin query = SELECT goto FROM alias WHERE address='%s' AND active = '1' /etc/postfix/sql/mysql_virtual_alias_domain_maps.cf

user = postfixadmin password = P4ssvv0rD hosts = 127.0.0.1 dbname = postfixadmin query = SELECT goto FROM alias, alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('%u', '@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1' /etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf

user = postfixadmin password = P4ssvv0rD hosts = 127.0.0.1 dbname = postfixadmin query = SELECT goto FROM alias, alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1' /etc/postfix/sql/mysql_virtual_mailbox_maps.cf

user = postfixadmin password = P4ssvv0rD hosts = 127.0.0.1 dbname = postfixadmin query = SELECT maildir FROM mailbox WHERE username='%s' AND active = '1' /etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf

user = postfixadmin password = P4ssvv0rD hosts = 127.0.0.1 dbname = postfixadmin query = SELECT maildir FROM mailbox, alias_domain WHERE alias_domain.alias_domain = '%d' and mailbox.username = CONCAT('%u', '@', alias_domain.target_domain) AND mailbox.active = 1 AND alias_domain.active='1'

לאחר יצירת קבצי תצורת SQL, עדכן את קובץ התצורה הראשי של Postfix כך שיכלול מידע על התחומים הווירטואליים, המשתמשים והכינויים המאוחסנים בבסיס הנתונים MySQL.

sudo postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/sql/mysql_virtual_domains_maps.cf" sudo postconf -e "virtual_alias_maps = mysql:/etc/postfix/sql/mysql_virtual_alias_maps.cf, mysql:/etc/postfix/sql/mysql_virtual_alias_domain_maps.cf, mysql:/etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf" sudo postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/sql/mysql_virtual_domains_maps.cf" sudo postconf -e "virtual_alias_maps = mysql:/etc/postfix/sql/mysql_virtual_alias_maps.cf, mysql:/etc/postfix/sql/mysql_virtual_alias_domain_maps.cf, mysql:/etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf" sudo postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/sql/mysql_virtual_mailbox_maps.cf, mysql:/etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf" sudo postconf -e "virtual_alias_maps = mysql:/etc/postfix/sql/mysql_virtual_alias_maps.cf, mysql:/etc/postfix/sql/mysql_virtual_alias_domain_maps.cf, mysql:/etc/postfix/sql/mysql_virtual_alias_domain_catchall_maps.cf" sudo postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/sql/mysql_virtual_mailbox_maps.cf, mysql:/etc/postfix/sql/mysql_virtual_alias_domain_mailbox_maps.cf" הפקודה postconf מציגה את הערכים בפועל של פרמטרי תצורה, משנה את ערכי פרמטרי התצורה או מציגה מידע נוסף על תצורה אודות מערכת הדואר Postfix.

סוכן המסירה המקומי יעביר את המיילים הנכנסים לתיבות הדואר של המשתמשים. הפעל את הפקודה הבאה להגדרת שירות LMTP של Dovecot כהובלת ברירת מחדל למשלוח דואר:

sudo postconf -e "virtual_transport = lmtp:unix:private/dovecot-lmtp"

קבע את הפרמטרים של TL באמצעות אישור SSL של בואו להצפין בעבר:

sudo postconf -e 'smtp_tls_security_level = may' sudo postconf -e 'smtpd_tls_security_level = may' sudo postconf -e 'smtp_tls_note_starttls_offer = yes' sudo postconf -e 'smtpd_tls_loglevel = 1' sudo postconf -e 'smtpd_tls_received_header = yes' sudo postconf -e 'smtpd_tls_cert_file = /etc/letsencrypt/live/mail.linuxize.com/fullchain.pem' sudo postconf -e 'smtpd_tls_key_file = /etc/letsencrypt/live/mail.linuxize.com/privkey.pem'

קבע את התצורה של הגדרות ה- SMTP המאומתות והסר את האימות ל- Dovecot:

sudo postconf -e 'smtpd_sasl_type = dovecot' sudo postconf -e 'smtpd_sasl_path = private/auth' sudo postconf -e 'smtpd_sasl_local_domain =' sudo postconf -e 'smtpd_sasl_security_options = noanonymous' sudo postconf -e 'broken_sasl_auth_clients = yes' sudo postconf -e 'smtpd_sasl_auth_enable = yes' sudo postconf -e 'smtpd_recipient_restrictions = permit_sasl_authenticated, permit_mynetworks, reject_unauth_destination'

נצטרך גם לערוך את קובץ התצורה של המאסטר Postfix master.cf ולאפשר את יציאת ההגשה ( 587 ) ויציאת ה- smtps ( 465 ).

פתח את הקובץ עם עורך הטקסט שלך ובטל את הסימון / ערוך את השורות הבאות:

/etc/postfix/master.cf

submission inet n - y - - smtpd -o syslog_name=postfix/submission -o smtpd_tls_security_level=encrypt -o smtpd_sasl_auth_enable=yes # -o smtpd_reject_unlisted_recipient=no -o smtpd_client_restrictions=permit_sasl_authenticated, reject # -o smtpd_helo_restrictions=$mua_helo_restrictions # -o smtpd_sender_restrictions=$mua_sender_restrictions # -o smtpd_recipient_restrictions= # -o smtpd_relay_restrictions=permit_sasl_authenticated, reject -o milter_macro_daemon_name=ORIGINATING smtps inet n - y - - smtpd -o syslog_name=postfix/smtps -o smtpd_tls_wrappermode=yes -o smtpd_sasl_auth_enable=yes # -o smtpd_reject_unlisted_recipient=no -o smtpd_client_restrictions=permit_sasl_authenticated, reject # -o smtpd_helo_restrictions=$mua_helo_restrictions # -o smtpd_sender_restrictions=$mua_sender_restrictions # -o smtpd_recipient_restrictions= # -o smtpd_relay_restrictions=permit_sasl_authenticated, reject -o milter_macro_daemon_name=ORIGINATING

הפעל מחדש את שירות לאחר התיקון לאחר שינויים ייכנסו לתוקף.

sudo systemctl restart postfix

בשלב זה הגדרת בהצלחה את שירות Postfix.

הגדר את ה- Dovecot

בחלק זה נקבע את Dovecot כך שיתאים להגדרה שלנו. הקפד לערוך את השורות המודגשות בצהוב.

התחל על ידי קביעת התצורה של קובץ dovecot-sql.conf.ext המורה ל- Dovecot כיצד לגשת למסד הנתונים וכיצד למצוא את המידע אודות חשבונות דוא"ל.

/etc/dovecot/dovecot-sql.conf.ext

driver = mysql connect = host=127.0.0.1 dbname=postfixadmin user=postfixadmin password=P4ssvv0rD default_pass_scheme = MD5-CRYPT iterate_query = SELECT username AS user FROM mailbox user_query = SELECT CONCAT('/var/mail/vmail/', maildir) AS home, \ CONCAT('maildir:/var/mail/vmail/', maildir) AS mail, \ 5000 AS uid, 5000 AS gid, CONCAT('*:bytes=', quota) AS quota_rule \ FROM mailbox WHERE username = '%u' AND active = 1 password_query = SELECT username AS user, password FROM mailbox \ WHERE username = '%u' AND active='1'

אל תשכח להשתמש בתעודות MySQL הנכונות (שם db, משתמש וסיסמא).

בשלב הבא, ערוך את conf.d/10-mail.conf וערוך את המשתנים הבאים:

/etc/dovecot/conf.d/10-mail.conf

… mail_location = maildir:/var/mail/vmail/%d/%n… mail_uid = vmail mail_gid = vmail… first_valid_uid = 5000 last_valid_uid = 5000… mail_privileged_group = vmail… mail_plugins = quota…

כדי לגרום לאימות לעבוד, פתח את conf.d/10-auth.conf , ערוך את השורות הבאות וכולל את קובץ ה- auth-sql.conf.ext :

/etc/dovecot/conf.d/10-auth.conf

… disable_plaintext_auth = yes… auth_mechanisms = plain login… #!include auth-system.conf.ext !include auth-sql.conf.ext…

פתח את conf.d/10-master.conf ושנה אותו באופן הבא:

/etc/dovecot/conf.d/10-master.conf

… service lmtp { unix_listener /var/spool/postfix/private/dovecot-lmtp { mode = 0600 user = postfix group = postfix }… }… service auth {… unix_listener auth-userdb { mode = 0600 user = vmail group = vmail }… unix_listener /var/spool/postfix/private/auth { mode = 0666 user = postfix group = postfix }… }… service auth-worker { user = vmail }… service dict { unix_listener dict { mode = 0660 user = vmail group = vmail } }…

פתח את conf.d/10-ssl.conf והפעל SSL / TLS.

/etc/dovecot/conf.d/10-ssl.conf

… ssl = yes… ssl_cert = Make sure you use the correct path to the SSL certificate files.


If you have followed this series from the beginning, you should already have the fullchain.pem , privkey.pem , dhparam.pem files created on your server. For more information about how to create a free Let's encrypt SSL certificate and Diffie–Hellman key check this tutorial.


Thanks to Nevyn for noticing the problem and providing a solution.
… ssl = yes… ssl_cert = Make sure you use the correct path to the SSL certificate files.


If you have followed this series from the beginning, you should already have the fullchain.pem , privkey.pem , dhparam.pem files created on your server. For more information about how to create a free Let's encrypt SSL certificate and Diffie–Hellman key check this tutorial.


Thanks to Nevyn for noticing the problem and providing a solution.

פתח את conf.d/20-imap.conf והפעל את התוסף imap_quota :

/etc/dovecot/conf.d/20-imap.conf

… protocol imap {… mail_plugins = $mail_plugins imap_quota… }…

פתח את conf.d/20-lmtp.conf וערוך אותו באופן הבא:

/etc/dovecot/conf.d/20-lmtp.conf

… protocol lmtp { postmaster_address = [email protected] mail_plugins = $mail_plugins }…

הגדר את תיבות הדואר המוגדרות כברירת מחדל בקובץ conf.d/20-lmtp.conf :

/etc/dovecot/conf.d/15-mailboxes.conf

… mailbox Drafts { special_use = \Drafts } mailbox Spam { special_use = \Junk auto = subscribe } mailbox Junk { special_use = \Junk }…

ישנם שני סוגים שונים של גדלי מכסות, האחד מוגדר לדומיין כולו והשני לכל תיבת דואר של משתמש. בחלק הקודם של הסדרה כבר הפעלנו את תמיכת המכסה ב- PostfixAdmin שפירושה שמידע המכסה יאוחסן במסד הנתונים של PostfixAdmin.

כעת עלינו לקבוע את התצורה של Dovecot להתחבר למסד הנתונים, לטפל במגבלות המכסה ולהריץ סקריפט ששולח דואר למשתמש כאשר מכסת המשתמש חורגת מהמגבלה שצוינה. לשם כך פתח את conf.d/90-quota.conf ושנה אותו באופן הבא:

/etc/dovecot/conf.d/90-quota.conf

plugin { quota = dict:User quota::proxy::sqlquota quota_rule = *:storage=5GB quota_rule2 = Trash:storage=+100M quota_grace = 10%% quota_exceeded_message = Quota exceeded, please contact your system administrator. quota_warning = storage=100%% quota-warning 100 %u quota_warning2 = storage=95%% quota-warning 95 %u quota_warning3 = storage=90%% quota-warning 90 %u quota_warning4 = storage=85%% quota-warning 85 %u } service quota-warning { executable = script /usr/local/bin/quota-warning.sh user = vmail unix_listener quota-warning { group = vmail mode = 0660 user = vmail } } dict { sqlquota = mysql:/etc/dovecot/dovecot-dict-sql.conf.ext }

עלינו גם לספר ל- dovecot כיצד לגשת למילון SQL המכסה. פתח את הקובץ dovecot-dict-sql.conf.ext וערוך את השורות הבאות:

/etc/dovecot/dovecot-dict-sql.conf.ext

… connect = host=127.0.0.1 dbname=postfixadmin user=postfixadmin password=P4ssvv0rD… map { pattern = priv/quota/storage table = quota2 username_field = username value_field = bytes } map { pattern = priv/quota/messages table = quota2 username_field = username value_field = messages }… # map { # pattern = shared/expire/$user/$mailbox # table = expires # value_field = expire_stamp # # fields { # username = $user # mailbox = $mailbox # } # }… וודא שאתה משתמש בתעודות MySQL הנכונות (שם db, משתמש וסיסמא).

צור את סקריפט הפגז הבא שישלח דוא"ל למשתמש אם המכסה שלו חורגת מהמגבלה שצוינה:

/usr/local/bin/quota-warning.sh

#!/bin/sh PERCENT=$1 USER=$2 cat << EOF | /usr/lib/dovecot/dovecot-lda -d $USER -o "plugin/quota=dict:User quota::noenforcing:proxy::sqlquota" From: [email protected] Subject: Quota warning Your mailbox is now $PERCENT% full. EOF

הפוך את הסקריפט להפעלה על ידי הפעלת הפקודה chmod הבאה:

sudo chmod +x /usr/local/bin/quota-warning.sh

לבסוף הפעל מחדש את שירות ה- dovecot כדי שינויים ייכנסו לתוקף.

sudo systemctl restart dovecot

סיכום

כעת עליך להיות בעל מערכת דואר פונקציונאלית לחלוטין. בחלק הבא בסדרה זו נראה לך כיצד להתקין ולשלב את Rspamd.

שרת דואר

פוסט זה הוא חלק מההגדרה והגדרת התצורה של סדרת שרתי דואר.

פוסטים אחרים בסדרה זו:

• הגדרת שרת דואר באמצעות PostfixAdmin • התקנה והגדרת תצורה של Postfix ו- Dovecot • התקנה ושילוב של Rspamd • התקנה והגדרת תצורת דואר אלקטרוני של Roundcube