⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch16_01.htm

📁 by Randal L. Schwartz and Tom Phoenix ISBN 0-596-00132-0 Third Edition, published July 2001. (See
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<html><head><title>Email Connectivity (Perl in a Nutshell, 2nd Edition)</title><link rel="stylesheet" type="text/css" href="../style/style1.css" /><meta name="DC.Creator" content="Stephen Spainhour" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly &amp; Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="0596002416L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="Perl in a Nutshell, 2nd Edition" /><meta name="DC.Type" content="Text.Monograph" /></head><body bgcolor="#ffffff"><img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Java and XSLT" /><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch15_02.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228" /><td align="right" valign="top" width="228"><a href="ch16_02.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><h1 class="chapter">Chapter 16. Email Connectivity</h1><div class="htmltoc"><h4 class="tochead">Contents:</h4>  <p> <a href="#perlnut2-CHP-16-SECT-1">The Net Modules</a><br /><a href="ch16_02.htm">The Mail Modules</a><br /></p></div><p>Electronic mail is arguably the most essential Internet application.In fact, for many people, it's their introduction tothe Internet. Thus, the Perl modules that deal with email are amongthe most useful modules. There are two major groups of modules thatprovide email capabilities. The first group <a name="INDEX-1991" /></a><a name="INDEX-1992" /></a><a name="INDEX-1993" /></a><a name="INDEX-1994" /></a><a name="INDEX-1995" /></a>isGraham Barr's <em class="emphasis">libnet</em>collection, which contains packages for developing client-sideapplications over the Internet in Perl. <a href="ch16_01.htm#perlnut2-CHP-16-TABLE-1">Table 16-1</a>lists some of the protocols implemented by the<em class="emphasis">libnet</em> modules.</p><a name="perlnut2-CHP-16-TABLE-1" /></a><h4 class="objtitle">Table 16-1. Protocols implemented by the libnet modules </h4><table border="1" cellpadding="3"><tr><th><p>Protocol</p></th><th><p>Module</p></th><th><p>Description</p></th></tr><tr><td><p>POP3</p></td><td><p>Net::POP3</p></td><td><p>Post Office Protocol, for reading email</p></td></tr><tr><td><p>SMTP</p></td><td><p>Net::SMTP</p></td><td><p>Simple Mail Transfer Protocol, for sending email</p></td></tr><tr><td><p>FTP</p></td><td><p>Net::FTP</p></td><td><p>File Transfer Protocol, for transferring files between hosts</p></td></tr><tr><td><p>NNTP</p></td><td><p>Net::NNTP</p></td><td><p>Network News Transfer Protocol, for reading Usenet news</p></td></tr></table><p><p>In this chapter, we discuss Net::SMTP and Net::POP3. <a href="ch17_01.htm">Chapter 17, "Usenet News"</a> talks about Net::NNTP, <a href="ch18_01.htm">Chapter 18, "FTP"</a> discussesNet::FTP, and <a href="ch19_01.htm">Chapter 19, "Lightweight Directory Access with Net::LDAP"</a> covers Net::LDAP. Other<em class="emphasis">libnet</em> modules, such as Net::SNPP and Net::Time,are not <a name="INDEX-1996" /></a>described in this book, but you canget information about them from CPAN or with the<em class="emphasis">perldoc</em> command if <em class="emphasis">libnet</em>is installed on your system.</p><p>The second group of mail-related modules are the Mail modules, whichcan be found on CPAN as<a name="INDEX-1997" /></a><a name="INDEX-1998" /></a><a name="INDEX-1999" /></a><a name="INDEX-2000" /></a><a name="INDEX-2001" /></a>the MailTools collection. Other interestingmail-related modules include Mail::Folder and its subclasses,Mail::RBL, Mail::Audit, and Unix::AliasFile. This chapter describesthe following subset of the Mail modules:</p><dl><dt><i>Mail::Send</i></dt><dd>Built on top of Mail::Mailer, providing better control of mail headers<p></p></dd><dt><i>Mail::Mailer</i></dt><dd>Interacts with external mail programs to send mail<p></p></dd><dt><i>Mail::Folder</i></dt><dd>Provides a base class and subclasses to work with mail folders<p></p></dd><dt><i>Mail::Internet</i></dt><dd>Provides functions to manipulate a mail message<p></p></dd><dt><i>Mail::Address</i></dt><dd>Extracts and manipulates RFC 822-compliant mail addresses<p></p></dd><dt><i>Mail::RBL</i></dt><dd>Provides domain lookups to the Real-time Blackhole List (RBL)<p></p></dd><dt><i>Mail::Audit</i></dt><dd>Provides an easy interface for creating mail filters<p></p></dd><dt><i>Unix::AliasFile</i></dt><dd>Perl interface to <em class="emphasis">/etc/aliases</em> format files<p></p></dd></dl><p>The rest of this chapter describes the Net modules and the Mailmodules.</p><div class="sect1"><a name="perlnut2-CHP-16-SECT-1" /></a><h2 class="sect1">16.1. The Net Modules</h2><p>Net::SMTP and Net::POP3 are the modules for sending and receivingemail via the SMTP and POP3 protocols. When you use these modules,you are working at the socket level; they directly implement theInternet protocols for sending and receiving mail as defined in therelevant RFCs: RFC 821 for SMTP and RFC 1081 for POP3.</p><a name="perlnut2-CHP-16-SECT-1.1" /></a><div class="sect2"><h3 class="sect2">16.1.1. Send Email with Net::SMTP</h3><p><a name="INDEX-2002" /></a><a name="INDEX-2003" /></a><a name="INDEX-2004" /></a><a name="INDEX-2005" /></a><a name="INDEX-2006" /></a>The Simple Mail Transfer Protocol, orSMTP, is responsible for clients negotiating RCPT("to") and FROM("from") requests with an SMTPserver, sending data to the SMTP server, and then sending anend-of-data indicator. Net::SMTP is a subclass of Net::Cmd andIO::Socket::INET that implements an interface to the SMTP and ESMTPprotocols. These protocols send mail by talking to an SMTP serverthrough a socket, as described in RFC 821.</p><p>When would you want to use Net::SMTP instead of sending mail with anexternal program? Since socket communications don'tinvolve spawning an external program, your programswon't suffer from the overhead associated withrunning an extra process. Talking to SMTP is convenient for sending avolume of mail messages. Naturally, your server must have an SMTPserver running, or a remote mailhost must allow you to talk to it;otherwise, you won't be able to use this module.That's when you can turn to Mail::Mailer orMail::Send and let them provide an interface to an external mailprogram for you. This is the case, for example, with home computers,which don't generally run their own SMTP server.</p></div><a name="perlnut2-CHP-16-SECT-1.2" /></a><div class="sect2"><h3 class="sect2">16.1.2. The SMTP Protocol and the SMTP Session</h3><p>The SMTP protocol defines the set of commands a client sends to anSMTP server, which is generally bound to port 25 of a mailhost.Requests and responses are negotiated between client and server.</p>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -