E-Mail System
Mail (1) Type, Type, charset - -
printable, base64
-
Length, MessageID, … -
7bit, quoted 8bit, binary Date, From, Date, From, To, Content Content No checking consistent “To” in envelope and header – – – – – Plain text only Plaintext MIME contents(attachments)Various Invisible to users Invisible whom to itbe delivered,or Determine wheretheshould message be should returned in RFC2822 themessages, definedInformation about The message body The message The envelope The headers The
• • • Three major components major Three
ComponentsE of an
Computer Center, CS, NCTU 2
Mail (2) -
Headers, which can be forged, altered, etc. altered, forged, be can which Headers, Body
• • You can really see … see You reallycan
ComponentsE of an
Computer Center, CS, NCTU 3
mail boxesmail
’
(DA)
(AA)
Place mails in users inmails Place mail theagentto user theConnects protocols or IMAP POP3 usingbox Delivery Delivery Agent Access Agent • •
(MTA)
(SA)
(MUA)
Help user read and compose mails compose and read user Help MTA local tomails Route machines among mails Route Submission Submission Agent Mail Transport Agent Mail User Agent
• • •
Major components Mail System
Computer Center, CS, NCTU 4
… ,
virus
image, image, video, – The User Agent (1) Agent UserThe
Include several types of content that canbe encodedseveralof that in the mail contentInclude types Originally: Text onlyTextOriginally: Now: MIME – MIME (Multipurpose Internet Mail Extensions) Mail Internet (Multipurpose MIME UA must know mail format mail know must UA
※
• Help user read and compose mails compose and Help user read
Mail System Mail
Computer Center, CS, NCTU 5
SMTP
IMAP
POP
MIME
muttrc - - - User Config. .mailrc . - -
Muttrc /
etc / - - - - - System Config. mail.rc
The User Agent (2) Agent UserThe
–
Popular Mail User Agents User Mail Popular
•
Mail System Mail Thunderbird In Smartphones Outlook Ep.Outlook Outlook MS mail mutt Netscape User Agent User
Computer Center, CS, NCTU 6
MessageID Date DomainKeys/DKIM – – –
The Submission Agent Submission The
Loggingerrors … SA theloadLetto share Ensuring that all hostname are fully qualifiedhostname areEnsuring thatfully all headersModifying – RFC2476 introduces the idea of splitting MTA splitting of idea the introduces RFC2476 Typical works that a MTA must do: must MTA a that works Typical
• • Route mails to local MTA local to mails Route
Mail System Mail
Computer Center, CS, NCTU 7 addresses, and addresses,
’
5321(2008)
MeTA1
http://www.postfix.org/ http://www.sendmail.org/ …
X
, … ,
RFC 2821RFC sendmail , RFC 821 RFC – – – The Transport Transport The (1) Agent
sendmail Postfix exim SMTP (Simple Mail Transport Protocol) (Simple MailTransportSMTP SMTP) (ExtendedESMTP – Popular transport agents transport Popular Accept mail from UA, examine the recipients the examine UA, from mail Accept host correct the to mail the delivery Protocols
• • • Route mails among machines among mails Route
Mail System Mail
Computer Center, CS, NCTU 8
The Transport Transport The (2) Agent
– Threat of eavesdropping of Threat
• Conversation between MTAs between Conversation
Mail System Mail
Computer Center, CS, NCTU 9
haha to:
Connection closed by foreign host. foreign by closed Connection mail from:
.
Id: <[email protected]> Id: -
haha
25 ... I spammed you! I spammed ...
The Transport Transport The (3) Agent
Message (CST) +0800 14:59:53 2012 1 May Tue, Date: hehe From: From: [email protected] To: – csmailgate
csmailgate
Protocol: SMTP Protocol: bsd5.cs.nctu.edu.tw 8BITMIME PIPELINING 204800000 SIZE VRFY ETRN ENHANCEDSTATUSCODES csmailgate.cs.nctu.edu.tw
------ Mail System Mail telnet 250 DSN 250 250 250 250 250 250 Connected to Connected is '^]'. character Escape Postfix ESMTP csmailgate.cs.nctu.edu.tw 220 ehlo 250 $ 140.113.235.103... Trying
Computer Center, CS, NCTU 10
郵件過濾設定 _ - _ 設定
mailboxes
’
procmail bogofilter
– – The Delivery Delivery The Agent
Do something between mail coming in and stored in mail box in mail stored in and coming mail between something Do https://help.cs.nctu.edu.tw/help/index.php/ User Program – procmail Accept mail from MTA and deliver the mail to the local local the to mail the deliver and MTA from mail Accept recipients of recipients Type
• • • Place mails in users in mails Place
Mail System Mail
Computer Center, CS, NCTU 11
Version 3)
–
The AccessThe Agent
IMAP (InternetAccess Protocol)IMAP Message (Post Office Protocol POP3 – Protocols
• Help user download mail from server from mail Help user download
Mail System Mail
Computer Center, CS, NCTU 12
host
” ucbvax “ at
” winsor “
host to the user
”
castle “ Domain Domain (1)
– [email protected] [email protected] Ex: Ex: castle!sun!sierra!hplabs!ucbvax!winsor This mail is sent from – – – Simply identify the final destinationthefinalidentify Simply Format: Message will travel through several intermediatetravelwill to thedestinationhosts Message through several host!path!user Format: Location independent address independent Location Route based address (obsolete) address based Route
• • Two kinds of email addresses: of email Two kinds
Mail Addressing
Computer Center, CS, NCTU 13
one to
” higher preference record)
A
cs.nctu.edu.tw “ Domain Domain (2)
–
If there is any servers, try until success from the the lower If no records, MX mail it directly to the host ( – –
First, lookup up the mail exchanger of up theFirst, lookup exchanger mail cs.nctu.edu.tw. 3600 IN MX 5 csmx2.cs.nctu.edu.tw. 5 MX IN 3600 cs.nctu.edu.tw. csmx3.cs.nctu.edu.tw. 10 MX IN 3600 cs.nctu.edu.tw. csmx1.cs.nctu.edu.tw. 5 MX IN 3600 cs.nctu.edu.tw. $ dig mx cs.nctu.edu.tw mx $ dig SECTION: ANSWER ;; When you want to send a mail to [email protected], the MTA MTA the [email protected], to mail a send to want you When will:
• Where to send the mail? thesend to Where
Mail Addressing
Computer Center, CS, NCTU 14
? ” Domain Domain (3)
– Mail eXchanger Mail “ We can centralize all the mail tasks to group of servers of group to tasks mail the all centralize can We robust more it make exchangers mail Multiple
• • Why Why using
Mail Addressing
Computer Center, CS, NCTU 15
Alias
–
mail looping mail weight Directory Access Protocol) Access Directory weight - based method based - based method based call LDAP name servertheLDAP and returnresultsthe callto resolve look up files to itself resolvelook up files by Be careful of of Be careful -
LDAP(Light File LDAP Map a username to something else something to username a Map files in method: Traditional NIS with method Traditional
• • • • • • When the mail server wants to resolvename to serverwants mail the When Several mechanisms to define aliases: to define mechanisms Several Alias
Mail Addressing
Computer Center, CS, NCTU 16
wide alias file alias wide - wide alias file can be server’s filein mail specified canalias wide -
wide /etc/mail/aliases file /etc/mail/aliases wide
- s configuraiton file configuraiton s
’ s forwarding file, ~/.forward file, forwarding s ’ Traditional Traditional aliasing mechanism (1)
configuration fileconfiguration aftersystemDA Read by forward(5) Read by MUA and expand the alias before injecting the message intomessage MUA beforeinjectingtheand expandtheRead aliasby the systemmail DA Read by Thepathsystemto the – In user In In MUA In system the In
• • • Aliases can be defined in three places three in defined be Aliases can
Mail Alias Mail
Computer Center, CS, NCTU 17
chiahung huanghs liuyh changlp cychao wangth pmli Contents of TA Contents of
…
filename /local/mail/TA usr include: : huanghs,chiahung,liuyh
ta : [email protected] :
name: name: name: recipient1,recipient2, name: - - ta: :include:/ta: admin: liuyh root: Traditional Traditional aliasing mechanism (2)
– Local Ex: Local Ex:
• 2. • The format of an entry in aliases file in aliases an entry of format The 1.
Mail Alias Mail
Computer Center, CS, NCTU 18
troadm
”
troublemail ”
/local/mail/
file usr - ftpserver path" -
path - ofprogram
/null /local/mail/logs/ : :include:/: /local/bin/ usr dev / : / : stdin usr |/ trouble_admin,trouble_log |/home/nahw1/receive.pl “ “ :
name: "|program name: name: absolute name: - - nahw1: trouble_admin trouble_log autoftp complaints: troubles: Traditional Traditional aliasing mechanism (3)
– Local to mail Route Ex: Local file this to appendedbe will Mails Ex:
• 4. • • • 3. The format of an entry in aliases file in aliases an entry of format The
Mail Alias Mail
Computer Center, CS, NCTU 19
command to rebuild the hashed version when you when version hashed the to rebuild command
”
newaliases Traditional Traditional aliasing mechanism (4) “
The file read from “:include:” is outside the aliases fileis “:include:”readoutsidethe from Thefile – /etc/mail/aliases is the plaintext aliases information aliases plaintext the is /etc/mail/aliases efficiency for version hashed the is /etc/mail/aliases.db Use file aliases the change
• • • The hashed aliases DB hashed aliasesThe
Mail Alias Mail
Computer Center, CS, NCTU 20
separated -
Traditional Traditional aliasing mechanism (5) liuyh, [email protected], [email protected] [email protected], liuyh,
to onlyuser should be writableThepathto .forward file [email protected] \
– Must be owned by user and with permission of600 permission with and user by be owned Must In ~/.forward In comma Format: Ex:
• • • • User maintainable forwarding file User maintainable
Mail Alias Mail
Computer Center, CS, NCTU 21
root root root root postmaster root root
DAEMON: postmaster DAEMON:
-
bind: daemon: games: kmem: mailnull: nobody: root operator: … MAILER root postmaster: bin:
… DAEMON -
/root/.forward aliases – – Traditional Traditional aliasing mechanism (6) forward root mail to the administratorforward to root mail the
Mail system maintainerMailsystem accounts(root) System – postmaster and MAILER and postmaster nobody, daemon, sys, bin, root
• • • Alias must Alias
Mail Alias Mail
Computer Center, CS, NCTU 22 sends a email to user sends email a
mroe.cs.colorado.edu [email protected] % dig mx anchor.cs.colorado.edu mx dig %
• User [email protected]
Mail Transport Example
Computer Center, CS, NCTU 23
06) - 04 -
Hsiang Hsiang Liu • Defined by RFC2822 by Defined Mail Headers (1) Computer Center, CS, NCTU 24 [127.0.0.1]) 8 localhost - 06) ) - 04 - ) chwong Encoding: Encoding: 8bit - chwong@localhost from from [email protected]) 8?B?56yR54uX5aW95Y+v5oCV?= - - - 8?B?5aSn5bCP5aeQ?= To: [email protected] - Hsiang Liu Path: Original - 你趕快把牠趕跑好不好? Content Content User RO Status: Content Lines: 1 To: Yung To: Subject: =?utf Message MIME Content Date:+0800 14:05:04 Wed, Apr18 2007 From: =?utf Received: from ( chbsd.cs.nctu.edu.tw Received: (from Return X Delivered [140.113.17.212]) Received: from (chbsd.csie.nctu.edu.tw chbsd.cs.nctu.edu.tw From [email protected] Wed Apr 18 14:07:21 2007 Apr 14:07:21 Wed 18 From [email protected] Mail Headers (2) Computer Center, CS, NCTU 25 record in ” Date and time and Date Received 、 “ s mailbox ’ Mail server software in receiving machine receivingin software serverMail 、 address ” From “ Receiving machine Receiving 、 800 (PST) - To: evi@rupertsberg To: - Unique queue identifier of mail server in receiving machine receiving in server mail of identifier queue Unique Sending machine Sending Path: [email protected]: – - Final envelope “rcpt to” Every machine that is ever processed this mail will add a top of headers Added by mail.local Addedmail.local by when the mail is put in user Used to separate message boundary The envelope “mail from” Used to send the error message to this address May be different to the Delivered [127.0.0.1]) byfrom (localhostReceived:knecht.sendmail.org 1 Oct id Fri with GAA18984; ESMTP (8.9.3/8.9.2)knecht.sendmail.org 06:04:02 1999 From [email protected] Return • • • • Headers in the example the in Headers Mail Headers (3) Computer Center, CS, NCTU 26 0700 - 800 (PST) - knecht.sendmail.org 0700 (MST) 700 (MST) - - Fri, Fri, 07:04:2511999 Oct (8.9.3/8.9.2) with ESMTP id [127.0.0.1]) by (more.cs.colorado.edu [128.138.243.1]) by localhost (knecht.sendmail.org (knecht.sendmail.org [209.31.233.160]) by ( ; Fri, 1 Oct 199907:04:24 ; Fri, 1 Oct 199907:04:23 (8.9.3/8.9.2) with ESMTP id HAA26176for (8.9.3/8.9.2) with ESMTP id froHAA09899 columbine.cs.colorado.edu knecht.sendmail.org more.cs.colorado.edu knecht.sendmail.org anchor.cs.Colorado.EDU Computer Center, CS, NCTU 27 800 - s MTA ’ version 2.0.2 2/24/98 2.0.2 version exmh Id: <[email protected]) Id: - standardheader information Nemeth Evi Add by sender Add by MUA Non Mailer: Mailer: - Date: Fri, 1 Oct 1999 06:04:021999 1 Oct Fri, Date: X To: hi Re: Subject: Message • • • • • Mail Headers (5) Computer Center, CS, NCTU 28 s name login ’ and root:mail as the owner and group owner theowner and root:mailgroup as and ” x 2 root mail x 2 root mail Dec 16mail/ 512 15:51 - 775 “ mails are stored in files named with each user named are in filesstored eachwith mails ’ Eg. /var/mail/liuyh drwxrwxr – – When the organization is large or for ISP with millions of customers of with or is for ISP millions largeWhen theorganization categorizeto search, Easy Users Permission Using database Using Usually the directory: /var/mail or /var/spool/mail or /var/mail directory: the Usually • • The place on the local machine where email is storedis email where machine localon the place The Mail Storage Computer Center, CS, NCTU 29 The issue of file lockingof Theissue file Has MTA to let you send and receive mail and yousend Has MTA toletreceive storagefor Provides mailboxes download mail PC from to letIMAP or youProvides POP3 Mail servers for incoming and/or outgoing mails outgoing and/or incoming for servers Mail mailboxes for Storage clients remote and PC integrate to POP3or IMAP Only one machine one Only • • • • architecture system mail in a Components Simplest architecture Simplest Mail System Architecture Computer Center, CS, NCTU 30 out server or or out server - medium sites medium – Mail home can be another host or one thecansame Mailhome host and forward mail MSA run to the same Eachmail directlymail the send Scalable architecture for architecture Scalable At least one machine for incoming message and message incoming for machine one least At message outgoing for machine one least At • • Centralize Mail System Architecture Architecture System Mail Computer Center, CS, NCTU 31 mail the right people rightthe mail - is used when you want other want you when used is is for people you want to know about know to want you people for is is for people that the message directly affects, and that that and affects, directly message the that people for is “No checking consistent “To” in envelope and header” and envelope in “To” consistent checking “No To field field To field copy) Cc (or carbon Copy) Carbon (Blind field Bcc to know they got it. got they knowto Why The from. action you require The involved. directly notare but message, the The recipients other the want you don't but message, the receive to people • • • • There are “To” and “Cc,” but not “Bcc” in the email headers. email the in “Bcc” not but and “Cc,” “To” are There You should always make you e sure make alwaysYou should To, Cc, and Bcc and Cc, To, Computer Center, CS, NCTU 32 33 responder - default database file for dbm(3) for file database default send to message default default database file for db(3)for file database default liuyh, |/usr/bin/vacation liuyh, mail mail auto ~/.vacation.msg \ returns a message, ~/.vacation.msg by default ~/.vacation.msg a message, returns ~/.vacation.db ~/.vacation.{dir,pag} - • • • • • Use with forward(5) E vacation(1) Computer Center, CS, NCTU 33