110 likes | 257 Views
Electronic Mail. CIT 383: Administrative Scripting. Topics. MTAs SMTP Message Stores POP and IMAP. MTAs. Mail Transport Agents use SMTP protocol Receive mail from MUAs. Route mail across internet. Examples sendmail postfix qmail exim MS Exchange. SMTP Example.
E N D
Electronic Mail CIT 383: Administrative Scripting CIT 383: Administrative Scripting
CIT 383: Administrative Scripting Topics • MTAs • SMTP • Message Stores • POP and IMAP
CIT 383: Administrative Scripting MTAs Mail Transport Agents use SMTP protocol • Receive mail from MUAs. • Route mail across internet. Examples • sendmail • postfix • qmail • exim • MS Exchange
CIT 383: Administrative Scripting SMTP Example 220 brahms.nku.edu ESMTP Sendmail 8.13.3; Wed, 12 Apr 2006 helo mydomain.com 250 brahms.nku.edu Hello mydomain.com, pleased to meet you mail from: me@mydomain.com 250 2.1.0 me@mydomain.com... Sender ok rcpt to: friend@nku.edu 250 2.1.5 friend@nku.edu... Recipient ok data 354 Enter mail, end with "." on a line by itself Subject: Test From: me@mydomain.com To: friend@nku.edu This is a test. . 250 2.0.0 k3GIcr001606 Message accepted for delivery quit 221 2.0.0 brahms.nku.edu closing connection
CIT 383: Administrative Scripting SMTP Commands HELO hostname EHLO hostname MAIL FROM: addr RCPT TO: addr VRFY addr EXPN addr DATA QUIT RSET HELP
CIT 383: Administrative Scripting SMTP in Ruby require 'net/smtp' message = <<EOM From: #{from} To: #{to} Subject: smtp test This is a test message. EOM smtp = Net::SMTP.new(server, 25) smtp.start do |smtp| smtp.send_message(message, to, from) end
CIT 383: Administrative Scripting Message Store Communication • Receives data from MDA (mail.local, procmail) • Provides data to MAA (IMAP, POP, NFS, web) Types of stores • Files (all messages for a user in one file) • Directories (directory per user) • Databases
CIT 383: Administrative Scripting POP and IMAP POP: Post Office Protocol • Simple download protocol for offline reading. IMAP: Internet Mail Access Protocol • Online and offline modes of reading. • Partial message fetch (headers, attachments, etc.) • Message state stored on server, not client. • Multiple mailbox and multiple client support.
CIT 383: Administrative Scripting POP3 Example S: +OK POP3 server ready <1896.697170952@dbc.mtview.ca.us> C: APOP mrose c4c9334bac560ecc979e58001b3e22fb S: +OK mrose's maildrop has 2 messages (320 octets) C: STAT S: +OK 2 320 C: LIST S: +OK 2 messages (320 octets) S: 1 120 S: 2 200 S: . C: RETR 1 S: +OK 120 octets S: <the POP3 server sends message 1> S: . C: DELE 1 S: +OK message 1 deleted C: QUIT S: +OK dewey POP3 server signing off (maildrop empty)
CIT 383: Administrative Scripting Accessing Mail in Ruby Files (mbox format) require ‘mailread’ mbox = Mail.new(fh) POP require ‘net/pop’ pop = Net::POP3.new(server) pop.start(user, pass) IMAP require ‘net/imap’ imap = Net::IMAP.new(server) imap.login(user, pass)
CIT 383: Administrative Scripting References • Michael Fitzgerald, Learning Ruby, O’Reilly, 2008. • David Flanagan and Yukihiro Matsumoto, The Ruby Programming Language, O’Reilly, 2008. • Hal Fulton, The Ruby Way, 2nd edition, Addison-Wesley, 2007. • Robert C. Martin, Clean Code, Prentice Hall, 2008. • Dave Thomas with Chad Fowler and Andy Hunt, Programming Ruby, 2nd edition, Pragmatic Programmers, 2005.