Levelezés

Linux levelezés telepítése

Telepítsünk egy alap levelezést Ubuntu 14.04-en mysql alapokon webfelülettel, az alábbi összetevőkkel:

  • postfix
  • dovecot
  • amavis
  • roundcube

Postfix működési elve

A postfix egy MTA, (Mail Transfer Agent), amely a rendszerébe beérkező levelek továbbításáért felelős. A postfix két nagyon fontos alrendszert ad: smtp szerver és smtp kliens.

Az smtp szerver az a réteg, amelyen keresztül a levelek smtp protokoll segítségével érkezhetnek be a rendszerébe. Az smtp szerveren keresztül érkező levelek – beállítástól függően – áthaladhatnak különféle ellenőrző, szűrő és egyéb programokon, feltételeken, amelyek segítenek eldönteni a levéllel kapcsolatos teendőket (alapvetően elutasítás, elfogadás).

Az smtp szerver a standard 25-ös portra kapcsolódva várja a klienseket, amelyeknek – beállítástól függően – authentikálniuk kellene.

Az smtp szerver portjai:

  • 25
  • 465 (SSL / TLS)
  • 587 (submission)

Az smtp kliens réteg feladata levelek továbbítása. Ez két irányba történhet: belső, lokális postafiókba, illetve külső levelező szerverek irányába. Az smtp szerver a beérkező levélről eldönti, hogy saját hatáskörbe tartozik vagy továbbítania kell. A saját hatáskörű levelet a helyi kézbesítő programnak adja át, amely megfelelő beállítással a megfelelő fizikai postafiókba teszi a levelet, tehát a végső kézbesítésért nem a postfix a felelős. A külső levelezőszerverek irányába az smtp kliens a felelős.

Az smtp protokollon kívül van még egy másik módszer, amellyel levél juttatható be a rendszerbe, ez pedig a sendmail program. A sendmail tulajdonképpen közvetlenül a queue rendszerbe juttatja be a leveleket, így azok az smtp szervernél beállított ellenőrzéseken nem mennek keresztül.

Alap programok telepítése

Postfix telepítése:

apt-get install postfix postfix-mysql postfix-pcre

Dovecot telepítése:

apt-get install dovecot-core dovecot-imapd dovecot-pop3d dovecot-mysql
apt-get install dovecot-managesieved dovecot-sieve mail-stack-delivery

Spam-, és vírusszűrés:

apt-get install amavisd-new-postfix

clamav / amavis közös munkához jobb ha a clamav az amavis csoport tagja (különben nem lesz joga olvasni a vírus szűrésre küldött tartalmat):

usermod -a -G amavis clamav

Levelek tárolásához linux user beállítása:

adduser --home /home/vmail/ --uid 5000 --disabled-login vmail
chmod 700 /home/vmail

Roundcube telepítése:

apt-get install roundcube-mysql roundcube roundcube-core 
apt-get install roundcube-plugins roundcube-plugins-extra

Postfix beállítása

A postfix beállításait két fájlban találjuk: /etc/postfix/main.cf és /etc/postfix/master.cf

A main.cf tartalmazza a postfix beállításait, míg a master.cf a postfix belső folyamatainak beállításait.

Először a main.cf-ben állítsuk be a legfontosabb paramétereket: hálózat, továbbítások, adatforrások (ezeket később vázoljuk), stmp szerver autentikácó, SSL/TLS paraméterek, smtp szerver ellenőrzési paraméterek.

Nem túlkonfigurált beállítások a main.cf-ben:

# SENDING AND RECEIVING MAIL
myhostname = /etc/mailname
myorigin = /etc/mailname
mydestination = $myorigin, localhost
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
message_size_limit = 31457280


# TRUST AND RELAY CONTROL
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
#relay_domains = $mydestination
relayhost =


# ALIAS DATABASE
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases

disable_vrfy_command = yes

# SMTPD AUTH
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/dovecot-auth
smtpd_sasl_authenticated_header = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain =
broken_sasl_auth_clients = yes

# SMTP CLIENT AUTH
smtp_sasl_security_options =
smtp_use_tls = yes


# ellenorzesi sorend
#1. smtpd_client_restrictions
#2. smtpd_helo_restrictions
#3. smtpd_sender_restrictions
#4. smtpd_recipient_restrictions
#5. smtpd_data_restrictions

smtpd_helo_required = yes
#smtpd_helo_restrictions =
#    reject_invalid_hostname,
#    permit

smtpd_sender_restrictions =
    permit_mynetworks,
    permit_sasl_authenticated,
    reject_unknown_sender_domain

smtpd_recipient_restrictions =
    reject_non_fqdn_sender,
    reject_non_fqdn_recipient,
    permit_mynetworks,
    permit_sasl_authenticated,
    reject_unauth_destination,
    reject_rbl_client b.barracudacentral.org,
    reject_rbl_client zen.spamhaus.org,
    #reject_rbl_client dnsbl.sorbs.net,
    #reject_rbl_client list.dsbl.org,
    #reject_rbl_client bl.spamcop.net,
    reject_rbl_client cbl.abuseat.org,
    #check_policy_service inet:127.0.0.1:60000,
    #check_policy_service unix:private/policy-spf
    #reject_invalid_hostname,
    #reject_non_fqdn_hostname,
    #reject_unknown_sender_domain,

#smtpd_data_restrictions =
#    reject_unauth_pipelining,
#    permit

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination

# TLS parameters
smtpd_tls_cert_file = /etc/dovecot/dovecot.pem
smtpd_tls_key_file = /etc/dovecot/private/dovecot.pem
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_tls_received_header = yes
smtpd_tls_mandatory_protocols = SSLv3, TLSv1
smtpd_tls_mandatory_ciphers = medium
smtpd_tls_auth_only = no
smtpd_tls_loglevel = 1
tls_random_source = dev:/dev/urandom

#CONTENT FILTERING
content_filter = smtp-amavis:[localhost]:10024
policy-spf_time_limit = 3600s

Magam részéről a permit_mynetworks paramétert sem szoktam alkalmazni, mert ha a hálózatunkban van olyan levelezőszerver, amely rosszul konfigurált (pl backup mx funkciójú),  akkor az rbl listás szerverek levelei ugyanúgy bejuthatnak, mintha mi nem is állítottuk volna be ezt explicit módon. Döntse el mindenki a maga vérmérséklete szerint, hogy mennyire tud megbízni, ide most azért tettem be, mert általában használni szokták.

Hozzuk létre a mysql adatbázis hátteret. Elsőnek is egy külön adatbázist, amelyben az alábbi sql utasításokat futtassuk le:

CREATE TABLE `domain` (
  `domainid` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `idn` varchar(100) COLLATE utf8_bin DEFAULT NULL,
  `domain` varchar(100) COLLATE utf8_bin DEFAULT NULL,
  `email` tinyint(1) unsigned NOT NULL DEFAULT '1',
  `smtp` tinyint(1) unsigned NOT NULL DEFAULT '1',
  PRIMARY KEY (`domainid`),
  UNIQUE KEY `idn` (`idn`),
  KEY `domain` (`domain`),
  KEY `email` (`email`),
  KEY `smtp` (`smtp`),
  KEY `idn_2` (`idn`,`email`),
  KEY `idn_3` (`idn`,`smtp`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin
CREATE TABLE `mailbox` (
  `mailboxid` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `domainid` int(10) unsigned NOT NULL,
  `email` varchar(100) COLLATE utf8_bin NOT NULL,
  `destination` text COLLATE utf8_bin,
  `password` varchar(100) COLLATE utf8_bin DEFAULT NULL,
  `home` varchar(255) COLLATE utf8_bin DEFAULT NULL,
  `uid` int(10) unsigned DEFAULT NULL,
  `gid` int(10) unsigned DEFAULT NULL,
  `state` enum('ACTIVE','NOT_ACTIVE') COLLATE utf8_bin NOT NULL DEFAULT 'ACTIVE',
  PRIMARY KEY (`mailboxid`),
  UNIQUE KEY `mailbox_2` (`email`),
  KEY `mailbox` (`email`,`state`),
  KEY `domainid` (`domainid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin
CREATE TABLE `mailalias` (
  `mailaliasid` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `source` varchar(100) COLLATE utf8_bin NOT NULL,
  `destination` text COLLATE utf8_bin NOT NULL,
  PRIMARY KEY (`mailaliasid`),
  UNIQUE KEY `source` (`source`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin

/etc/postfix mappában hozzunk létre két könyvtárt: sasl, virtual

mkdir /etc/postfix/{sasl,virtual}

A sasl könyvtár fogja tartalmazni az smtp authentikáció paramétereit (esetünkbe mysql lekérdezés). Itt hozzunk létre egy smtpd.conf fájlt:

touch /etc/postfix/sasl/smtpd.conf

Az smtpd.conf fájl tartalma:

pwcheck_method: saslauthd
mech_list: plain login cram-md5 digest-md5
allow_plaintext: true
auxprop_plugin: mysql
sql_hostnames: localhost:3306
sql_user: mysql user name
sql_passwd: mysql user password
sql_database: mysql database name
sql_select: select m.password from mailbox m, domain d where d.domainid = m.domainid AND m.email = '%u' AND m.state = 'ACTIVE' and d.smtp = 1

A /etc/postfix/virtual könyvtár fogja tartalmazni a postafiókok, domainek paramétereit (esetünkben mysql lekérdezéseket). A postfix alapvetően ún. lookup table types (adat táblákkal ) dolgozik. A lényege az, hogy többféle adatforrásból származó adatot tudjon kezelni.  Adatforrás típusai lehetnek:

  • lista (szöveges felsorolás), amelynek tulajdonképpen nincs is típusa
  • hash (postmap-el indexelt/hashelt szöveges fájlok),
  • mysql (mywql client lekérdezéssel)
  • tcp (tcp kliens, ip és port megadásával)

Részletes lista: http://www.postfix.org/DATABASE_README.html#types

A fájlok (csak a nagyon alapok):

/etc/postfix/virtual/mysql-domains.cf

user = mysql user
password = mysql password
dbname = mysql database
query = SELECT idn AS virtual FROM domain WHERE idn='%s' and email=1
hosts = localhost:3306

/etc/postfix/virtual/mysql-email-maps.cf

user = mysql user
password = mysql password
dbname = mysql database
query = SELECT email FROM mailbox WHERE email='%s'
hosts = localhost:3306

/etc/postfix/virtual/mysql-mailbox-maps.cf

user = mysql user
password = mysql password
dbname = mysql database
query = SELECT CONCAT(SUBSTRING_INDEX(email,'@',-1),'/',SUBSTRING_INDEX(email,'@',1),'/') FROM mailbox WHERE email='%s'
hosts = localhost:3306

/etc/postfix/virtual/mysql-alias-maps.cf

user = mysql user
password = mysql password
dbname = mysql database
query = SELECT destination FROM mailalias WHERE source='%s'
hosts = localhost:3306

A fájlok elnevezése lényegtelenek, ezeket később úgyis explicit kell megadni a postfix beállításaiban.

Most, hogy elkészültünk az adatbázis háttérrel, illetve létrehoztuk az adatforrásokat, magát a postfixet kell beállítani ahhoz, hogy ezeket használja is. Adjuk meg az /etc/postfix/main.cf fájlban (annak végéhez fűzve):

#VIRTUAL ENVIRONMENT
virtual_alias_domains =
virtual_alias_maps = proxy:mysql:/etc/postfix/virtual/mysql-alias-maps.cf, proxy:mysql:/etc/postfix/virtual/mysql-email-maps.cf
virtual_mailbox_domains = proxy:mysql:/etc/postfix/virtual/mysql-domains.cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/virtual/mysql-mailbox-maps.cf
virtual_mailbox_base = /home/vmail
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000

Adjuk meg, hogy a lokális kézbesítésért melyik program a felelős (esetünkben a dovecot) az /etc/postfix/main.cf fájlban (annak végéhez fűzve):

#LOCAL TRANSPORT
virtual_transport = dovecot
dovecot_destination_recipient_limit = 1
mailbox_command = /usr/lib/dovecot/deliver -c /etc/dovecot/dovecot.conf -m "${EXTENSION}"

Továbbiakban a postfix folyamatait állítjuk be.

Van egy – talán csak – magyar vonatkozású probléma: az internet szolgáltatók némelyike szűri a 25-ös portra irányuló forgalmat, és ha az nem a saját szervereik irányába megy, azt eldobják. Ezt magam részéről felháborítónak tartom, de tenni ellene egyelőre nem tudok. A felhasználóknak adhatunk kikerülési lehetőséget, éspedig úgy, hogy megnyitunk egy másik portot is a 25-ös mellé. Én a 26-ost szoktam. A fentieken kívül még érdemes beállítani a submission-t és az smtps-t.

A korábbi telepítéseknek köszönhetően a vírusszűrésre vonatkozó beállítások már bekerültek ide. A lényege az, hogy a vírus-, és spamszűrés egy külön alrendszer feladata (amavis), a postfix és az amavis közötti adatcsere és kapcsolattartás paraméterei vannak itt konfigurálva. A postfix tcp/smtp alapokon adja át a teljes levelet az amavisnak, amely szűrés után szintén hasonló módszertannal adja vissza a levelet a postfix-nak (a header-ök bővültek az ellenőrzés eredményével).

Egy minta /etc/postfix/master.cf fájlra:

smtp      inet  n       -       -       -       -       smtpd
26      inet  n       -       -       -       -       smtpd
#smtp      inet  n       -       -       -       1       postscreen
#smtpd     pass  -       -       -       -       -       smtpd
#dnsblog   unix  -       -       -       -       0       dnsblog
#tlsproxy  unix  -       -       -       -       0       tlsproxy
submission inet n       -       -       -       -       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=$mua_client_restrictions
#  -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 smtpd_recipient_restrictions=permit_sasl_authenticated,reject_unauth_destination,reject
#  -o milter_macro_daemon_name=ORIGINATING
smtps     inet  n       -       -       -       -       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=$mua_client_restrictions
#  -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 smtpd_recipient_restrictions=permit_sasl_authenticated,reject
  -o smtpd_sasl_security_options=noanonymous,noplaintext
  -o smtpd_sasl_tls_security_options=noanonymous
#  -o milter_macro_daemon_name=ORIGINATING
#628       inet  n       -       -       -       -       qmqpd
pickup    unix  n       -       -       60      1       pickup
cleanup   unix  n       -       -       -       0       cleanup
qmgr      unix  n       -       n       300     1       qmgr
#qmgr     unix  n       -       n       300     1       oqmgr
tlsmgr    unix  -       -       -       1000?   1       tlsmgr
rewrite   unix  -       -       -       -       -       trivial-rewrite
bounce    unix  -       -       -       -       0       bounce
defer     unix  -       -       -       -       0       bounce
trace     unix  -       -       -       -       0       bounce
verify    unix  -       -       -       -       1       verify
flush     unix  n       -       -       1000?   0       flush
proxymap  unix  -       -       n       -       -       proxymap
proxywrite unix -       -       n       -       1       proxymap
smtp      unix  -       -       -       -       -       smtp
relay     unix  -       -       -       -       -       smtp
#       -o smtp_helo_timeout=5 -o smtp_connect_timeout=5
showq     unix  n       -       -       -       -       showq
error     unix  -       -       -       -       -       error
retry     unix  -       -       -       -       -       error
discard   unix  -       -       -       -       -       discard
local     unix  -       n       n       -       -       local
virtual   unix  -       n       n       -       -       virtual
lmtp      unix  -       -       -       -       -       lmtp
anvil     unix  -       -       -       -       1       anvil
scache    unix  -       -       -       -       1       scache
#
# ====================================================================
# Interfaces to non-Postfix software. Be sure to examine the manual
# pages of the non-Postfix software to find out what options it wants.
#
# Many of the following services use the Postfix pipe(8) delivery
# agent.  See the pipe(8) man page for information about ${recipient}
# and other message envelope options.
# ====================================================================
# 
# maildrop. See the Postfix MAILDROP_README file for details.
# Also specify in main.cf: maildrop_destination_recipient_limit=1
#
maildrop  unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
# 
# ====================================================================
# 
# Recent Cyrus versions can use the existing "lmtp" master.cf entry.
#
# Specify in cyrus.conf:
#   lmtp    cmd="lmtpd -a" listen="localhost:lmtp" proto=tcp4
# 
# Specify in main.cf one or more of the following:
#  mailbox_transport = lmtp:inet:localhost
#  virtual_transport = lmtp:inet:localhost
# 
# ====================================================================
# 
# Cyrus 2.1.5 (Amos Gouaux)
# Also specify in main.cf: cyrus_destination_recipient_limit=1
#
#cyrus     unix  -       n       n       -       -       pipe
#  user=cyrus argv=/cyrus/bin/deliver -e -r ${sender} -m ${extension} ${user}
#
# ====================================================================
# Old example of delivery via Cyrus.
#
#old-cyrus unix  -       n       n       -       -       pipe
#  flags=R user=cyrus argv=/cyrus/bin/deliver -e -m ${extension} ${user}
#
# ====================================================================
#
# See the Postfix UUCP_README file for configuration details.
#
uucp      unix  -       n       n       -       -       pipe
  flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
#
# Other external delivery methods.
#
ifmail    unix  -       n       n       -       -       pipe
  flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp     unix  -       n       n       -       -       pipe
  flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
scalemail-backend unix  -       n       n       -       2       pipe
  flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
mailman   unix  -       n       n       -       -       pipe
  flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
  ${nexthop} ${user}

dovecot unix   -   n   n    -   -   pipe
    flags=DRhu user=vmail:vmail argv=/usr/lib/dovecot/dovecot-lda -f ${sender} -d ${user}@${nexthop} -m ${extension}
# ==========================================================================
# service type  private unpriv  chroot  wakeup  maxproc command + args
#               (yes)   (yes)   (yes)   (never) (100)
# ==========================================================================
# Added using postfix-add-policy script:
policy-spf unix    -       n       n       -       0     spawn
      user=nobody argv=/usr/bin/policyd-spf
# ==========================================================================
# service type  private unpriv  chroot  wakeup  maxproc command + args
#               (yes)   (yes)   (yes)   (never) (100)
# ==========================================================================
# Added using postfix-add-filter script:
smtp-amavis unix    -       -       -       -       2     smtp
     -o smtp_data_done_timeout=1200
     -o smtp_send_xforward_command=yes
     -o smtp_tls_note_starttls_offer=no
     
127.0.0.1:10025 inet n    -       -       -       -     smtpd
     -o content_filter=
     -o smtpd_delay_reject=no
     -o smtpd_client_restrictions=permit_mynetworks,reject
     -o smtpd_helo_restrictions=
     -o smtpd_sender_restrictions=
     -o smtpd_recipient_restrictions=permit_mynetworks,reject
     -o smtpd_data_restrictions=reject_unauth_pipelining
     -o smtpd_end_of_data_restrictions=
     -o smtpd_restriction_classes=
     -o mynetworks=127.0.0.0/8
     -o smtpd_error_sleep_time=0
     -o smtpd_soft_error_limit=1001
     -o smtpd_hard_error_limit=1000
     -o smtpd_client_connection_count_limit=0
     -o smtpd_client_connection_rate_limit=0
     -o receive_override_options=no_header_body_checks,no_unknown_recipient_checks,no_milters
     -o local_header_rewrite_clients=
     -o smtpd_milters=
     -o local_recipient_maps=
     -o relay_recipient_maps=

Indítsuk újra a:

service postfix restart

Amavis beállítása

Az amavist már telepítettük, ezzel együtt települt a spamassassin (spamszűrő) és a clam (víruszűrő). Tulajdonképpen az amavis egy wrapper program, amivel könnyebb a levelek szűrése. Ahelyett hogy a spamszűrést és a vírusszűrért külön-külön konfigurálnánk, az amavis segítségével egy helyen tudjuk ezt megtenni, és a postfix-ban is jelentősen könnyebb dolgunk van.

Amavis beállításokat az /etc/amavis/conf.d könyvtárban találjuk.

Itt a 15-content_filter_mode fájlban kommentezzük ki a szűrést (ezt kellene kapnunk):

@bypass_virus_checks_maps = (
   \%bypass_virus_checks, \@bypass_virus_checks_acl, $bypass_virus_checks_re);

@bypass_spam_checks_maps = (
   \%bypass_spam_checks, \@bypass_spam_checks_acl, $bypass_spam_checks_re);

Ezután a 20-debina-defaults fájlban szúrjuk be az alábbiakat az $quarantine_subdir_levels = 1; # enable quarantine dir hashing alá:

$mydomain = "ide általában a postfix $mydomain értéke mehet";
@lookup_sql_dsn = ( [ 'DBI:mysql:database=database name;host=localhost;port=3306', 'mysql user', 'mysql password' ] );
$sql_select_policy = 'SELECT "Y" as local FROM domain WHERE CONCAT("@",idn) IN (%k) AND email = 1';

$inet_socket_port = 10024;   # default listening socket sor alá:

@inet_acl = qw( 127.0.0.1 ::1 );

$sa_dsn_cutoff_level = 10; # spam level beyond which a DSN is not sent sor alá:

$sa_quarantine_cutoff_level = 9.0; # spam level beyond which quarantine is off

Állítsuk be az alábbi értékeket:

$sa_spam_subject_tag = '[SPAM]';
$sa_tag_level_deflt  = -1000; #2.0;  # add spam info headers if at, or above that level
$sa_tag2_level_deflt = 8.0; # 9.0; #6.31; # add 'spam detected' headers at that level
$sa_kill_level_deflt = 9.0; #6.31; # triggers spam evasive actions

Ezzel azt adtuk meg, hogy a spmanek minősülő levelek tárgyába beszúrja a [SPAM] előtagot, illetve behangoltuk (nem túl szigorúan) a spam szinteket.

Állítsuk be azt, hogy a spma leveleket is engedje be. Ezt azért szoktam beállítani, hogy a levél tulajdonosa tudja eldönteni, hogy mi történjen a spammel (és így a valójában nem spam levél nem megy a kukába). Későbbiekben beállítunk egy szűrőt, hogy a spam levelek a postafiók SPAM mappájába kerüljenek be.

Ezt a beállítást a 21-ubuntu_defaults fájlban is adjuk meg:

$final_spam_destiny       = D_PASS;

A 21-ubuntu_defaults fájlban érdemes lesz megadni egy vírus admin e-mail címet is (spam adminnak ne, túl sok levél jönne). Ide küld a rendszer a vírusos levelekről riportot.

$virus_admin = 'email cím';

Engedélyezzük a spamassassin-t az /etc/default/spamassassin fájlban:

ENABLED=1

Indítsuk el vagy újra az egészet:

service clamav-daemon start
service spamassassin start
service amavis restart

Dovecot beállítása

Beállításokat az /etc/dovecot könyvtárban találjuk. A lenti beállítások nem az adott fájl teljes tartalmára vonatkozik, csak a felsorolt paraméterek cseréjére (legtöbbjénél csak komment jelet kell törölni).

Az /etc/dovecot/dovecot-mysql.conf fájlban adjuk meg az alábbiakat:

driver = mysql
connect = host=127.0.0.1 dbname=database name user=mysql user password=mysql password port=3306
default_pass_scheme = PLAIN
password_query = \
    SELECT email as user, password FROM mailbox WHERE email = '%u' AND state = 'ACTIVE'

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

disable_plaintext_auth = no
auth_username_chars = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@

auth_mechanisms = plain login cram-md5 digest-md5

#!include auth-system.conf.ext
!include auth-sql.conf.ext
#!include auth-ldap.conf.ext
#!include auth-passwdfile.conf.ext
#!include auth-checkpassword.conf.ext
#!include auth-vpopmail.conf.ext
#!include auth-static.conf.ext

/etc/dovecot/conf.d/auth-sql.conf.ext fájl teljes tartalma:

passdb {
  driver = sql

  # Path for SQL configuration file, see example-config/dovecot-sql.conf.ext
  args = /etc/dovecot/dovecot-sql.conf.ext
}

# "prefetch" user database means that the passdb already provided the
# needed information and there's no need to do a separate userdb lookup.
# <doc/wiki/UserDatabase.Prefetch.txt>
#userdb {
#  driver = prefetch
#}

#userdb {
#  driver = sql
#  args = /etc/dovecot/dovecot-mysql.conf
#}

# If you don't have any user-specific settings, you can avoid the user_query
# by using userdb static instead of userdb sql, for example:
# <doc/wiki/UserDatabase.Static.txt>
userdb {
  driver = static
  args = uid=vmail gid=vmail home=/home/vmail/%u
}

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

log_path = /var/log/dovecot.log

plugin {
  # Events to log. Also available: flag_change append
  #mail_log_events = delete undelete expunge copy mailbox_delete mailbox_rename
  # Available fields: uid, box, msgid, from, subject, size, vsize, flags
  # size and vsize are available only for expunge and copy events.
  mail_log_fields = uid box msgid size from subject
}

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

mail_location = maildir:/home/vmail/%d/%n

/etc/dovcot/conf.d/10-sssl.conf

ssl = yes
ssl_cipher_list = ALL:!LOW:!SSLv2:ALL:!aNULL:!ADH:!eNULL:!EXP:RC4+RSA:+HIGH:+MEDIUM

/etc/dovcot/conf.d/15-lda.conf:

protocol lda {
  # Space separated list of plugins to load (default is global mail_plugins).
  mail_plugins = $mail_plugins sieve
}

/etc/dovecot/conf.d/20-managesieve.conf fájl teljes tartalma:

service managesieve-login {
  inet_listener sieve {
    port = 4190
  }

  #inet_listener sieve_deprecated {
  #  port = 2000
  #}

  # Number of connections to handle before starting a new process. Typically
  # the only useful values are 0 (unlimited) or 1. 1 is more secure, but 0
  # is faster. <doc/wiki/LoginProcess.txt>
  service_count = 1

  # Number of processes to always keep waiting for more connections.
  #process_min_avail = 0

  # If you set service_count=0, you probably need to grow this.
  vsz_limit = 64M
}

service managesieve {
  # Max. number of ManageSieve processes (connections)
  #process_count = 1024
}

# Service configuration

protocol sieve {
  # Maximum ManageSieve command line length in bytes. ManageSieve usually does
  # not involve overly long command lines, so this setting will not normally
  # need adjustment
  managesieve_max_line_length = 65536

  # Maximum number of ManageSieve connections allowed for a user from each IP
  # address.
  # NOTE: The username is compared case-sensitively.
  #mail_max_userip_connections = 10

  # Space separated list of plugins to load (none known to be useful so far).
  # Do NOT try to load IMAP plugins here.
  #mail_plugins =

  # MANAGESIEVE logout format string:
  #  %i - total number of bytes read from client
  #  %o - total number of bytes sent to client
  #managesieve_logout_format = bytes=%i/%o

  # To fool ManageSieve clients that are focused on CMU's timesieved you can
  # specify the IMPLEMENTATION capability that Dovecot reports to clients.
  # For example: 'Cyrus timsieved v2.2.13'
  #managesieve_implementation_string = Dovecot Pigeonhole
  
  # Explicitly specify the SIEVE and NOTIFY capability reported by the server
  # before login. If left unassigned these will be reported dynamically
  # according to what the Sieve interpreter supports by default (after login
  # this may differ depending on the user).
  #managesieve_sieve_capability =
  #managesieve_notify_capability =

  # The maximum number of compile errors that are returned to the client upon
  # script upload or script verification.
  #managesieve_max_compile_errors = 5

  # Refer to 90-sieve.conf for script quota configuration and configuration of
  # Sieve execution limits.
}

/etc/dovecot/conf.d/20-pop3.conf (nem kötelező, de problémákat akadályozhatunk meg azonos, de több párhuzamos pop3 fiók elérésnél):

pop3_reuse_xuidl = yes
pop3_lock_session = yes
pop3_save_uidl = yes
mail_max_userip_connections = 100

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

sieve = /home/vmail/%d/%u.dovecot.sieve
sieve_dir = ~/sieve
sieve_before = /etc/dovecot/sieve

Hozzunk létre egy /etc/dovecot/sieve könyvtárt, ebben spam-mail-to-spam-folder.sieve fájlt Ezzel fogjuk a spam levelek a SPAM folderbe irányítani.

mkdir /etc/dovecot/sieve
touch /etc/dovecot/sieve/spam-mail-to-spam-folder.sieve

/etc/dovecot/sieve/spam-mail-to-spam-folder.sieve tartalma:

require ["fileinto","mailbox"];
if header :contains "Subject" "[SPAM]" {
        fileinto :create "Spam";
        stop;
} else {
        keep;
}

/etc/dovecot/conf.d/99-mail-stack-delivery.conf:

protocols = imap pop3 sieve
disable_plaintext_auth = no
ssl = yes
ssl_cert = </etc/dovecot/dovecot.pem
ssl_key = </etc/dovecot/private/dovecot.pem
ssl_cipher_list = ALL:!LOW:!SSLv2:ALL:!aNULL:!ADH:!eNULL:!EXP:RC4+RSA:+HIGH:+MEDIUM
mail_location = maildir:/home/vmail/%d/%n
auth_username_chars = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890.-_@

Indítsuk újra:

service dovecot restart

Elképzelhető, hogy  nemlesz írási joga a postfix-nek a /var/log/dovecot.log fájlra. Ez mehet akkor a syslog-ba, vagy a létrejött fájlra teszel írási jogot.

Loading