PostfixPostfix 2 /usr/ports/mail/postfix http://www.postfix.org/documentation.html • • http://www.postfix.org Postfix v2.9.2 Postfix Postfix Postfix Computer Center, CS, NCTU 2 http://www.postfix.org/OVERVIEW.html Receive and deliverover email the network via SMTP Local delivery directly or use deliveryother agentmail • • • MTA that MTA Role Postfix of Role Postfix of Computer Center, CS, NCTU 3 C o m Postfix Architecture p Postfix Architecture u t e r C Modular-design MTA e n • Not like sendmail of monolithic system t e • Decompose into several individual program that each one handle r , specific task C S • The most important daemon: master daemon , Reside in memory N Get configuration information from master.cf and main.cf C T Invoke other process to do jobs U Major tasks • Receive mail and put in queue • Queue management • Delivery mail from queue 4 C o m PostfixPostfix ArchitectureArchitecture –– p u t MessageMessage ININ e r C Four ways e • Local submission n t postdrop command e r maildrop queue , C pickup daemon S cleanup daemon Local submission , – Header validation N – address translation C T incoming queue U • Network submission smtpd daemon • Local forwarding Resubmit for such as .forward Envelope “to” is changed • Notification 5 Network submission C o m PostfixPostfix ArchitectureArchitecture –– p u t QueueQueue e r C Five different queues e • incoming n t The first queue that every incoming email will stay e r • active , C Queue manager will move message into active queue whenever there is enough S system resources , Queue manager then invokes suitable DA to delivery it N C • deferred T Messages that cannot be delivered are moved here U These messages are sent back either with bounce or defer daemons • corrupt Used to store damaged or unreadable message • hold 6 http://www.postfix.org/QSHAPE_README.html#queues C o m PostfixPostfix ArchitectureArchitecture –– p u t MessageMessage OUTOUT –– PartPart II e r C Address classes e • Used to determine which destinations to accept for delivery n t e • How the delivery take place r , Main address classes C S • Local delivery , Domain names in “mydestination” is local delivered N C Ex: T – mydestination = nasa.cs.nctu.edu.tw localhost U It will check alias and .forward file to do further delivery • Relay Transfer mail for others to not your domain It is common for centralize mail architecture to relay trusted domain • Deliver mail to other domains for authorized user The queue manager will invoke the smtp DA to deliver this mail • Virtual alias • 7 Virtual mailbox s sendmail command command sendmail s ’ [email protected] ([email protected]) [email protected] Helene compose mail using her MUA, and then call postfix and then call MUA, using her mail compose Helene to it send [email protected] [email protected] Phase1: • • Example Message Flow in (1) Message Flow Postfix Message Flow in (1) Message Flow Postfix Computer Center, CS, NCTU 8 [email protected] The smtpd on postfix.org takes this The message and smtpd on invoke postfix.org cleanup then put in incoming queue find that frank is an alias,The so localit resubmits it DA through cleanup daemon for further delivery [email protected] [email protected] Phase2: • • Example Message Flow in (2) Message Flow Postfix Message Flow in (2) Message Flow Postfix Computer Center, CS, NCTU 9 [email protected] The smtpd on onlamp.com takes this message and invoke cleanup then put in incoming queue Local delivery to message store [email protected] [email protected] Phase3 • • Example Message Flow in (3) Message Flow Postfix Message Flow in (3) Message Flow Postfix Computer Center, CS, NCTU 10 C o m Message Store Format p Message Store Format u t e r C The Mbox format e • n Store messages in single file for each user t e • Each message start with ªFrom º line and continued with message headers r , and body C • Mbox format has file-locking problem S , The Maildir format N C • Use structure of directories to store email messages T U • Each message is in its owned file • Three subdirectories - cur, new, and tmp • Maildir format has scalability problem locate and delete mails quickly, but waste amounts of fd, inodes, space Problems of quota and backup Related parameters (in main.cf) • mail_spool_directory = /var/mail (Mbox) • mail_spool_directory = /var/mail/ (Maildir) 11 C o m Postfix & POP3/IMAP p Postfix & POP3/IMAP u t e r C POP3 vs. IMAP e n • Both are used to retrieve mail from server for remote clients t e • POP3 has to download entire message, while IMAP can download r , C headers only S • POP3 can download only single mailbox, while IMAP can let you , N maintain multiple mailboxes and folders on server C T Postfix works together with POP3/IMAP U • Postfix and POP3/IMAP must agree on the type of mailbox format and style of locking Standard message store Non-standard message store (using LMTP) – Such as Cyrus IMAP or Dovecot 12 C o m Postfix Configuration p Postfix Configuration u t e r C Two most important configuration files e n • /usr/local/etc/postfix/main.cf – postconf(5) t e Core configuration r , C • /usr/local/etc/postfix/master.cf – master(5) S Which postfix service should invoke which program , N C Edit main.cf T • U Using text editor • postconf % postconf [–e] "myhostname = nasa.cs.nctu.edu.tw" % postconf –d myhostname (print default setting) % postconf myhostname (print current setting) Reload postfix whenever there is a change • # postfix reload 13 C o m PostfixPostfix ConfigurationConfiguration –– p u t LookupLookup tablestables (1)(1) e r C Parameters that use external files to store values e • n Such as mydestination, mynetwork, relay_domains t e • Text-based table is ok, but time-consuming when table is large r , Lookup tables syntax C S • Key values % postconf -m , btree N Database format cidr C • % postconf ±m environ T hash U List all available database format internal • In main.cf proxy regexp default_database_type static % postconf default_database_type tcp default_database_type = hash texthash % postconf -h default_database_type unix hash • http://www.postfix.org/DATABASE_README.html 14 C o m PostfixPostfix ConfigurationConfiguration –– p u t LookupLookup tablestables (2)(2) e r C Use databased-lookup table in main.cf e • n syntax t parameter = type:name e r , • Ex: C In main.cf S , canonical_maps = hash:/usr/local/etc/postfix/canonical N After execute postmap C /usr/local/etc/postfix/canonical.db T U postmap command • Generate database # postmap hash:/usr/local/etc/postfix/canonical • Query % postmap ±q nctu.edu.tw hash:/usr/local/etc/postfix/canonical 15 C o m PostfixPostfix ConfigurationConfiguration –– p u t LookupLookup tablestables (3)(3) e r C Regular expression tables e n • More flexible for matching keys in lookup tables t e Sometimes you cannot list all the possibilities r , C • Two regular expression libraries used in Postfix S POSIX extended regular expression (regexp, default) , N Perl-Compatible regular expression (PCRE) C T • Usage U /pattern/ value Do some content checks, such as – header_checks – body_checks Design some features – /(\S+)\.(\S+)@nasa\.cs\.nctu\.edu\.tw/ [email protected] 16 C o m PostfixPostfix ConfigurationConfiguration –– p u t CategoriesCategories e r C Categories e • n Server identities t my... e r , • Mail rewriting C for incoming/outgoing mails S , • Access control N restrictions C T • Mail processing U filter • Operation details … 17 C o m PostfixPostfix ConfigurationConfiguration –– p u t MTAMTA IdentityIdentity e r C Four related parameters e • n myhostname t myhostname = nasa.cs.nctu.edu.tw e r , If un-specified, postfix will use ‘hostname’ command C • mydestination S , List all the domains that postfix should accept for local delivery N mydestination = $myhostname, localhost.$mydomain $mydomain C T – This is the CS situation that mx will route mail to mailgate U mydestination = $myhostname www.$mydomain, ftp.$mydomain • mydomain mydomain = cs.nctu.edu.tw If un-specified, postfix use myhostname minus the first component • myorigin myorigin = $mydomain (default is $myhostname) 18 C o m PostfixPostfix ConfigurationConfiguration –– p u t System-wideSystem-wide aliasesaliases filesfiles e r C Using aliases in Postfix (first-matching) e • n alias_maps = hash:/etc/aliases t e • alias_maps = hash:/etc/aliases, nis:mail.aliases r , • alias_database = hash:/etc/aliases C Tell newaliases command which aliases file to build S , To Build alias database file N C • % postalias /etc/aliases T U Alias file format (same as sendmail) • RHS can be Email address, filename, |command, :include: Alias restriction • allow_mail_to_commands = alias, forward • allow_mail_to_files = alias, forward 19 C o m PostfixPostfix ConfigurationConfiguration –– p u t VirtualVirtual AliasAlias MapsMaps e r C Virtual Alias Map e n • It recursively rewrites envelope recipient addresses for all local, all t e virtual, and all remote mail destinations. r , • C virtual_alias_domains = $virtual_alias_maps (default) S • virtual_alias_maps = hash:/usr/local/etc/postfix/virtual , N src-address dst-address C [email protected] @chbsd.cs.nctu.edu.tw T U chwong [email protected] @csie.nctu.edu.tw @cs.nctu.edu.tw • Applying regular expression virtual_alias_maps = pcre:/usr/local/etc/postfix/virtual /^root(\..+)?@(t)?(cs|np)?bsd\d*\.cs\.nctu\.edu\.tw$/ [email protected] /^root(\..+)?@(t)?(cs|np)?linux\d*\.cs\.nctu\.edu\.tw$/ [email protected] /^root(\..+)?@(t)?csmail\w*\d*\.cs\.nctu\.edu\.tw$/ [email protected] 20 C o m PostfixPostfix ConfigurationConfiguration –– p u t RelayRelay ControlControl (1)(1) e r C Open relay e n • A mail server that permit anyone to relay mails t e • By default, postfix is not an open relay r , C S , N A mail server should C • Relay mail for trusted user T U Such as [email protected] • Relay mail for trusted domain Ex.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages46 Page
-
File Size-