Tải bản đầy đủ - 0 (trang)
Chapter 23.  Transporting and Handling Email Messages

Chapter 23.  Transporting and Handling Email Messages

Tải bản đầy đủ - 0trang

Thereareanumberofpossiblescenariosforusingemailona

Linuxsystem,anddependingonthosescenarios,youwillhave

toinstalladifferentsetofsoftwarepackages.However,no

matterwhichoptionyouchoose,youwillalwaysneedamailer.

Thefirstscenarioappliestodial-upaccesstotheInternetvia

anInternetserviceprovider(ISP).Inthisscenario,thereis

oftenonlyoneuserontheLinuxmachine,althoughthisisnota

requirement.TheISPacceptsyourmailfromtheInternetand

storesitforyouonitsharddisks.Youcanthenretrievethe

mailwheneveryouwantbyusingthecommonPostOffice

Protocol(POP3)orthenewerInternetMessageAccessProtocol

(IMAP).Outgoingmailinthisscenarioisalmostexclusivelysent

viatheSMTPprotocol,whichisuniversallyusedtotransport

mailovertheInternet.

Intheeasiestcase,youuseyourmailerbothtoretrievethe

mailviaPOP3orIMAPandtosenditbackviaSMTP.Whenyou

dothis,youdonotevenneedtosetupanMTAbecausethe

mailerhandleseverything.Thisisnotterriblyflexible,butifall

youwantistoaccessyourmaileasily,thismightbeanoption

foryou.MailersthatsupportthisincludeKMailfromKDEand

Mozilla'sbuilt-inmailprogram(bothdescribedlater).

Browser-basedemailclientssuchasgmailorGMXareyet

anotherstory.Theyneedtooperateonamailboxthatisstored

onaserver;thismailboxcouldbefilledbyeitherPOP3orIMAP,

oftenautomatically.Thesedays,itisquitecommonfor

browser-basedemailclientstouseIMAP.

Ifyouwantmoreflexibility(whichcomesatthepriceofmore

configurationandmaintenancework),youcaninstallanMTA

suchasPostfix,describedinthenextsection.Youwillneeda

programthattransportsthemailfromyourprovider'sPOP3or

IMAPserver.Thisprogramfetchesyourmailwhenyouaskitto

andpassesthemessagesontotheMTArunningonyour

system,whichthendistributesthemailtotherecipients'mail

folders.Oneprogramthatdoesexactlythatisfetchmail,which



wecoverlaterinthischapter.Outgoingmailisagainsentvia

SMTP,butwithanMTArunningonyourmachine,youcan

choosenottosendtheoutgoingmessagesdirectlytoyour

provider'sSMTPserver,butrathertoyourownserver,whichis

providedbytheMTA.TheMTAthenforwardsthemailtoyour

provider,whichinturnsendsittotherecipients.Withthis

setup,youcaninstructyourMTAtosendoutgoingmailat

certainintervalssothatyoudonotalwayshavetomakeadialupconnection.

Thethirdscenarioismeantformachinesthathavea

permanentconnectiontotheInternet,eitherbecausetheyare

inanetworkthathasagatewaywithapermanentconnection,

orbecausetheyareusingaleasedlinetoyourInternet

provider.Inthiscase,youmightwanttoreceivemailmessages

assoonastheyarriveatyourproviderandnothavethem

storedthere.ThisalsorequiressettingupanMTA.Incoming

mailwillbedirectedtoyourSMTPserver(i.e.,yourMTA).Your

providerwillhavetosetthingsupaccordinglyforthistowork.

Ofcourse,therearemanymorescenariosforusingmail,and

mixturesbetweenthethreementionedarepossibleaswell.If

youaregoingtosetupamailserviceforawholenetwork,you

willmostcertainlywanttoreadtheLinuxNetwork

Administrator'sGuide(O'Reilly)aswellasabookaboutyour

MTA.

Youhaveanumberofsoftwarechoicesforsettingupemailona

Linuxhost.Wecan'tdescribealltheavailableemailsolutions,

butwedodescribesomepackagesthatareoftenusedand

quitesuitablefortheirrespectivetasks.Mailprogramsforend

users,suchasKMailandEvolution,havealreadybeen

describedindetailinpreviouschapters.Inthischapterwe

documentwhatwethinkarethemostpopularLinuxadvanced

toolsatthistime:thePostfixmailtransportagentandthe

fetchmailimplementationofthePOP3andIMAPprotocols.

Thesearerelativelysimpletoconfigurebutprovideallthe

featuresmostusersneed.Inaddition,withthesetools,youcan



coverallthescenariosdescribedearlier.



23.1.ThePostfixMTA

SeveralMTAsareavailableforLinux.Historically,themost

commonMTAonUnixhasbeensendmail,whichhasbeen

aroundforalongtime.Itisgenerallyconsideredsomewhat

moredifficulttousethanthealternatives,butitisthoroughly

documentedinthebooksendmail,byBryanCostaleswithEric

Allman(O'Reilly).

PostfixisanewerMTA,developedbysecurityguruWietse

Venemaasareplacementforsendmail.It'sdesignedtobe

compatiblewithsendmailbuttoprovideahigherlevelof

securityandbeeasiertoconfigure.

Postfixisahighlyflexibleandsecurepieceofsoftwarethat

containsmultiplelayersofprotectionagainstwould-be

attackers.Postfixwasalsowrittenwithperformanceinmind,

andemploystechniquestolimitsloweractivitiessuchas

creatingnewprocessesandaccessingthefilesystem.Itisone

oftheeasieremailpackagestoconfigureandadminister

becauseitusesstraightforwardconfigurationfilesandsimple

lookuptablesforaddressrewriting.Itisremarkableinthatitis

simpletouseasabasicMTA,yetstillabletohandlemuchmore

complicatedenvironments.

ManyLinuxdistributionshavePostfixbuiltin,soyoumay

alreadyhaveitinstalledonyoursystem.Ifnot,youcanfind

prebuiltpackagesorcompileityourselffromthesourcecode.

ThePostfixhomepage(http://www.postfix.org)containslinks

todownloadboththesourcecode("Download")andpackages

fordifferentLinuxdistributions("PackagesandPorts").

Postfixhastwodifferentreleasetracks:officialand

experimental.Theexperimentalreleasescontainallthelatest

patchesandnewfeatures,althoughthesemightchangebefore

theyareincludedintheofficialrelease.Don'tbeputoffbythe



term"experimental";thesereleasesareverystableandhave

beentestedthoroughly.Ifyouarelookingforafeaturethatis

availableonlyintheexperimentalrelease,youshouldfeelmore

thancomfortableusingit.Readthereleasenotesforboth

trackstoknowwhatthecurrentdifferencesare.



23.1.1.AWordAboutDNS

BeforesettingupPostfix,youshouldunderstandthatifyour

systemisgoingtoreceivemailfromothersacrosstheInternet,

theDNSforyourdomainhastobeconfiguredcorrectly.DNSis

discussedinChapter13.

Let'sassumeforthisdiscussionthatyouareconfiguringahost

calledhalointhedomainexample.organdthatyouhaveauser

accountmichaelonyoursystem.Regardlessofhowyouwantto

receivemail,yourhosthalo.example.orgmusthaveaDNSA

recordthatmapsitshostnametoitsIPaddress.

Inthisexampleyouremailaddressisgoingtobeeither

michael@halo.example.orgormichael@example.org.Ifyou

wanttousethefirstform,configuringtheDNSArecordis

enoughformessagestoreachyou.

Ifyoursystemisgoingtoreceiveallmailforexample.org

(includingmichael@example.org),thedomainshouldhavea

DNSMXrecordpointingtoyourhosthalo.example.org.Ifyouare

configuringtheDNSforyourdomainyourself,makesureyou

readthedocumentationtounderstandhowitworks;otherwise,

speaktoyourDNSadministratororISPaboutroutingmailto

yoursystem.

PostfixfrequentlyusesDNSinitsnormaloperation,andituses

theunderlyingLinuxlibrariestoperformitsDNSqueries.Make

sureyoursystemisconfiguredcorrectlytoperformDNS

lookups(see"ConfiguringDNS"inChapter13).Postfixusually



hastofindanMXrecordtomakeitsdeliveries.Don'tassume

thatifPostfixreportsaDNSproblemwithanaddress,andyou

findthatthedomainresolvescorrectly,thatemaildelivery

shouldthereforesucceed.IfPostfixreportsaproblem,youcan

bealmostcertainthereisaproblem.



23.1.2.InstallingPostfix

Althoughprepackageddistributionsareavailable,youmaywant

tobuildthepackageyourselfifyouwanttouseanyoftheaddonlibrariesorfunctionsthatarenotincludedinyour

distribution.Youmightalsowanttogetthelatestversionto

obtainanewfeaturethathasnotyetbeenincludedinyour

distribution.

BeforeyouinstallPostfix,beawarethatitincludesthethree

commands/usr/bin/newaliases,/usr/bin/mailq,and

/usr/sbin/sendmailthatarenormallyusedbysendmail.Postfix

providesreplacementsthatworkwiththePostfixsystemrather

thanwithsendmail.Youshouldrenameyourexistingsendmail

commandssothatthePostfixinstallationdoesn'toverwrite

themincaseyoueverwanttousetheoriginalsendmail

binariesagain:

#mv/usr/bin/newaliases/usr/bin/newaliases.orig

#mv/usr/bin/mailq/usr/bin/mailq.orig

#mv/usr/sbin/sendmail/usr/sbin/sendmail.orig



PostfixusesUnixdatabasefilestostoreitsaliasandlookup

tableinformation.Youmust,therefore,havethedblibraries

installedonyoursystembeforebuildingPostfix.Theselibraries

arecontainedwithinthedb-develRPMpackageortheDebian

libdb4.3-devpackage.Ifyouarenotusingapackagemanager,

youcanobtainthemdirectlyfromSleepycatSoftware



(http://www.sleepycat.com/).IfyouareusingRPM,executethe

followingcommandtoseeifthenecessarylibrarieshavebeen

installedonyoursystem:

#rpm-qa|grepdb-devel

db-devel-4.3.27-3



Youshouldseealinesimilartothesecondlineinthepreceding

commandthatdisplaysthedb-develpackagewithaversion

number.Ifrpmreturnsnothing,youmustinstallthelibraries

beforeinstallingPostfix.

OnDebian,youcanusedpkgtoseeifthelibrariesareinstalled:

#dpkg-llibdb4.3-dev



IfyoudownloadaprepackagedPostfix,useyourpackage

manager(describedinChapter12)toinstallit.Ifyoudownload

thesourcepostfix-2.2.5.tar.gz,movethatfiletoasuitable

directory(suchasyourhomedirectory)tounpackit.The

numbersinthenameofthefilerepresenttheversionofthis

release.Yourfilemayhavedifferentnumbersdependingonthe

currentreleasewhenyoudownloadit.

FollowthisbasicproceduretobuildPostfix.Notethatyou'll

havetobetherootusertocreatetheuserandgroupandto

installthepackage.

1. Renameyoursendmailbinariesasdescribedearlier.

2. Createauseraccountcalledpostfixandagroupcalled

postdrop.See"ManagingUserAccounts"inChapter11for

informationonsettingupaccountsandgroups.



3. Rungunziponthecompressedfiletoproduceafilenamed

postfix-2.2.5.tar.

4. Execute

tar-xvfpostfix-2.2.5.tar



tounpackthesourceintoadirectorycalledpostfix-2.2.5.

5. Movetothedirectorycreatedwhenyouunpackedthefile.

You'llfindafilecalledINSTALLwithdetailedinstructions

aboutbuildingyourPostfixsystem.Inmostcases,building

Postfixshouldbeassimpleastypingmakeinthedirectory.

6. Ifyourbuildcompleteswithoutanyerrors,typemake

installtoinstallPostfixonyoursystem.Youshouldbeable

toacceptallthedefaultswhenpromptedbytheinstallation

script.

Afterinstallation,youwillhavePostfixfilesinthefollowing

directories:



/usr/libexec/postfix

ThisdirectorycontainsthevariousPostfixdaemons.Postfix

usesasplitarchitectureinwhichseveraldiscreteprograms

handleseparatetasks.Themasterdaemonisstartedfirst.

Itdealswithstartingotherprogramsastheyareneeded.

Forthemostpart,youdon'tneedtoworryaboutanyofthe

programshere.StoppingandstartingPostfixishandled

withthepostfixcommandfoundinthe/usr/sbindirectory.



/etc/postfix



TypicallythisdirectorycontainsdozensofPostfix

configurationfiles,butonlymaster.cfandmain.cfandafew

lookuptablesareusedbyPostfix.Therestofthefilesare

examplesthatdocumentthevariousparametersusedfor

configuration.

Themaster.cffilecontrolsthevariousPostfixprocesses.It

includesalineforeachcomponentofPostfix.Thelayoutof

thefileisdescribedbycommentsinthefileitself.Usually,

youshouldn'thavetomakeanychangestorunasimple

Postfixinstallation.

Themain.cffileistheglobalSMTPconfigurationfile.It

includesalistofparameterssettooneormorevalues

usingtheformat

parameter=value



Commentsaremarkedwithahashmark(#)atthe

beginningoftheline.Youcannotputcommentsonthe

samelineasparameters.Commentedlinescanbeginwith

whitespace(spacesortabs),buttheymustappearonlines

bythemselves.

Multiplevaluesforparameterscanbeseparatedbyeither

commasorwhitespace(includingnewlines),butifyouwant

tohavemorethanonelineforaparameter,startthe

secondandsubsequentlineswithwhitespace.Valuescan

refertootherparametersbyprecedingtheparametername

withadollarsign($).

Here'sanexampleofanentrythatincludescomments,

multiplelines,andaparameterreference:

#HereareallthesystemsIacceptmailfrom.

mynetworks=$myhostname



192.168.75.0/24

10.110.12.15



/usr/sbin

AllthePostfixcommandsarelocatedin/usr/sbinandhave

namesstartingwithpost.Therearecommandstocreate

indexfiles,managethemailqueue,andotherwise

administeryourPostfixsystem.Thepostfixcommand,

whichisusedtostopandstartPostfix(describedlater),is

foundhere.



/var/spool/postfix

ThePostfixqueuemanagerisanimportantcomponentof

thePostfixsystemthatacceptsincomingemailmessages

andarrangeswithotherPostfixcomponentstodeliver

them.Itmaintainsitsfilesunderthe/var/spool/postfix

directory.Thequeuesitmaintainsareshownnext.Postfix

providesseveraltoolstomanagethequeues,suchas

postcat,postsuper,andmailq,butyoumightalsousethe

usualLinuxcommands,suchasfindandcat,toinspect

yourqueue.



/var/spool/postfix/incoming

Allincomingmessages,whetherfromoverthenetworkor

sentlocally.



/var/spool/postfix/active



Messagesthatthequeuemanagerisdeliveringorpreparing

todeliver.



/var/spool/postfix/deferred

Messagesthatcouldnotbedeliveredimmediately.Postfix

willattempttodeliverthemagain.



/var/spool/postfix/corrupt

Messagesthatarecompletelyunreadableorotherwise

damagedandnotdeliverablearestoredhereforyoutolook

atifnecessarytofigureouttheproblem.Thisqueueis

rarelyused.



/usr/local/man

Postfixinstallsdocumentationintheformofmanpageson

yoursystem.Thedocumentationincludesinformationon

command-lineutilities,daemons,andconfigurationfiles.

Asmentionedearlier,Postfixalsoinstallsreplacementsfor

/usr/bin/newaliases,/usr/bin/mailq,and/usr/sbin/sendmail.



23.1.3.PostfixConfiguration

BeforeyoustartPostfixforthefirsttime,youhavetomake

surethatthealiasestableisformattedcorrectlyandthatafew

ofthecriticalconfigurationparametersaresetcorrectlyforyour

system.



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Chapter 23.  Transporting and Handling Email Messages

Tải bản đầy đủ ngay(0 tr)

×