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

📄 ch09_06.htm

📁 用perl编写CGI的好书。本书从解释CGI和底层HTTP协议如何工作开始
💻 HTM
字号:
<?label 9.6. Perl Mailers?><html><head><title>Perl Mailers (CGI Programming with Perl)</title><link href="../style/style1.css" type="text/css" rel="stylesheet" /><meta name="DC.Creator" content="Scott Guelich, Gunther Birznieks and Shishir Gundavaram" /><meta scheme="MIME" content="text/xml" name="DC.Format" /><meta content="en-US" name="DC.Language" /><meta content="O'Reilly & Associates, Inc." name="DC.Publisher" /><meta scheme="ISBN" name="DC.Source" content="1565924193L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="CGI Programming with Perl" /><meta content="Text.Monograph" name="DC.Type" /></head><body bgcolor="#ffffff"><img src="gifs/smbanner.gif" alt="Book Home" usemap="#banner-map" border="0" /><map name="banner-map"><area alt="CGI Programming with Perl" href="index.htm" coords="0,0,466,65" shape="rect" /><area alt="Search this book" href="jobjects/fsearch.htm" coords="467,0,514,18" shape="rect" /></map><div class="navbar"><table border="0" width="515"><tr><td width="172" valign="top" align="left"><a href="ch09_05.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td width="171" valign="top" align="center"><a href="index.htm">CGI Programming with Perl</a></td><td width="172" valign="top" align="right"><a href="ch09_07.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr></table></div><hr align="left" width="515" /><h2 class="sect1">9.6. Perl Mailers</h2><p>There are <a name="INDEX-1910" /><a name="INDEX-1911" /> <a name="INDEX-1,912" />other programs you can use for sendingmail, but they are not as common. Some of these, such as<tt class="command">blat</tt>, provide simple mailers for Windows systems.Instead of looking at these, we'll look at a Perl solution thatworks across all operating systems.</p><p><a name="INDEX-1913" /><a name="INDEX-1914" />Mail::Mailer is a popular Perl modulefor sending Internet email. It provides a simple interface forsending messages with<tt class="command">sendmail</tt><a name="INDEX-1915" /> <a name="INDEX-1,916" /> and <tt class="command">mail</tt> (or<tt class="command">mailx</tt>). It also allows you to send messages via<a name="INDEX-1917" /><a name="INDEX-1918" />SMTPwithout an external application, which makes it possible to sendmessages on non-Unix systems like Windows and even the MacOS.</p><p>You can use Mail::Mailer this way:</p><blockquote><pre class="code">my $mailer = new Mail::Mailer ( "smtp" );$mailer-&gt;open( {    To       =&gt; $email,    From     =&gt; 'The Webmaster &lt;webmaster@scripted.com&gt;',    Subject  =&gt; 'Web Site Feedback'} );print $mailer &lt;&lt;END_OF_MESSAGE;Your message has been sent and someone should be responding to you shortly. Thanks for taking the time to provide us with your feedback!END_OF_MESSAGEclose $mailer;</pre></blockquote><p>When you create a Mail::Mailer object, you can specify whether youwant it to send the message one of three ways:</p><dl><dt><b><em class="emphasis">mail</em></b></dt><dd><p>Mail::Mailer will search your system for <tt class="command">mailx</tt>,<tt class="command">Mail</tt>, or <tt class="command">mail</tt> in that order anduse the first one it finds (we didn't discuss<tt class="command">Mail</tt>, although on many systems<tt class="command">Mail</tt> and <tt class="command">mail</tt> are thesame -- <tt class="command">mail</tt> is simply a symlink to<tt class="command">Mail </tt>).</p></dd><dt><b><em class="emphasis">sendmail</em></b></dt><dd><p>Mail::Mailer will use <tt class="command">sendmail</tt> to send mail.</p></dd><dt><b><em class="emphasis">smtp</em></b></dt><dd><p>Mail::Mailer will use the Net::SMTP Perl module to send mail.</p></dd></dl><p>If you do not specify an argument when you create an object,Mail::Mailer will search through each of these three options in orderand use the first one it finds When Mail::Mailer uses an externalmailer, it uses the <tt class="function">fork</tt> and<tt class="function">exec</tt> technique to avoid passing argumentsthrough the shell.</p><p>Mail::Mailer is primarily useful when you use it to send mail viaSMTP on systems without <tt class="command">sendmail</tt>. Even though itallows you to use <tt class="command">sendmail</tt> as its mailer, there isno way for you to specify command-line options the way you can if youuse <tt class="command">sendmail</tt> directly. Mail::Mailer only uses the<em class="emphasis">-t</em><a name="INDEX-1919" /> option when it calls<tt class="command">sendmail</tt>.</p><p>To send mail directly through SMTP with Mail::Mailer, you need tohave the <a name="INDEX-1920" /> <a name="INDEX-1,921" />Net::SMTP<a name="INDEX-1922" /> <a name="INDEX-1,923" />module, which is part of the<em class="emphasis">libnet</em> bundle available on CPAN. When youinstall this module, it should ask you for the SMTP server you use onyour network. If this was not configured when the module wasinstalled, you have two options. You can edit the installed<em class="filename">Net/Config.pm</em><a name="INDEX-1924" /> file in your Perl librariesfolder and add your SMTP server to the <tt class="literal">smtp_hosts</tt>element of the <tt class="literal">NetConfig</tt> hash at the bottom of thefile, or you can specify it when you create a Mail::Mailer object.You can do so like this:</p><blockquote><pre class="code">my $mailer = new Mail::Mailer ( "smtp", Server =&gt; $server );</pre></blockquote><p>In this example, <tt class="literal">$server</tt> would contain the name ofyour SMTP<a name="INDEX-1925" />server.Your network administrator or internet service provider should beable to provide you with the name of this machine.</p><hr align="left" width="515" /><div class="navbar"><table border="0" width="515"><tr><td width="172" valign="top" align="left"><a href="ch09_05.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td width="171" valign="top" align="center"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0" /></a></td><td width="172" valign="top" align="right"><a href="ch09_07.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr><tr><td width="172" valign="top" align="left">9.5. mailx and mail</td><td width="171" valign="top" align="center"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0" /></a></td><td width="172" valign="top" align="right">9.7. procmail</td></tr></table></div><hr align="left" width="515" /><img src="../gifs/navbar.gif" alt="Library Navigation Links" usemap="#library-map" border="0" /><p><font size="-1"><a href="copyrght.htm">Copyright &copy; 2001</a> O'Reilly &amp; Associates. All rights reserved.</font></p><map name="library-map"><area href="../index.htm" coords="1,1,83,102" shape="rect" /><area href="../lnut/index.htm" coords="81,0,152,95" shape="rect" /><area href="../run/index.htm" coords="172,2,252,105" shape="rect" /><area href="../apache/index.htm" coords="238,2,334,95" shape="rect" /><area href="../sql/index.htm" coords="336,0,412,104" shape="rect" /><area href="../dbi/index.htm" coords="415,0,507,101" shape="rect" /><area href="../cgi/index.htm" coords="511,0,601,99" shape="rect" /></map></body></html>

⌨️ 快捷键说明

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