Install Perl 5.8.8
[msysgit.git] / mingw / html / lib / Net / SMTP.html
blobec6344f65fe72364847b6aaaaefea9f89fb9aebb
1 <?xml version="1.0" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title>Net::SMTP - Simple Mail Transfer Protocol Client</title>
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 <link rev="made" href="mailto:" />
8 </head>
10 <body style="background-color: white">
11 <table border="0" width="100%" cellspacing="0" cellpadding="3">
12 <tr><td class="block" style="background-color: #cccccc" valign="middle">
13 <big><strong><span class="block">&nbsp;Net::SMTP - Simple Mail Transfer Protocol Client</span></strong></big>
14 </td></tr>
15 </table>
17 <p><a name="__index__"></a></p>
18 <!-- INDEX BEGIN -->
20 <ul>
22 <li><a href="#name">NAME</a></li>
23 <li><a href="#synopsis">SYNOPSIS</a></li>
24 <li><a href="#description">DESCRIPTION</a></li>
25 <li><a href="#examples">EXAMPLES</a></li>
26 <li><a href="#constructor">CONSTRUCTOR</a></li>
27 <li><a href="#methods">METHODS</a></li>
28 <li><a href="#addresses">ADDRESSES</a></li>
29 <li><a href="#see_also">SEE ALSO</a></li>
30 <li><a href="#author">AUTHOR</a></li>
31 <li><a href="#copyright">COPYRIGHT</a></li>
32 </ul>
33 <!-- INDEX END -->
35 <hr />
36 <p>
37 </p>
38 <h1><a name="name">NAME</a></h1>
39 <p>Net::SMTP - Simple Mail Transfer Protocol Client</p>
40 <p>
41 </p>
42 <hr />
43 <h1><a name="synopsis">SYNOPSIS</a></h1>
44 <pre>
45 use Net::SMTP;</pre>
46 <pre>
47 # Constructors
48 $smtp = Net::SMTP-&gt;new('mailhost');
49 $smtp = Net::SMTP-&gt;new('mailhost', Timeout =&gt; 60);</pre>
50 <p>
51 </p>
52 <hr />
53 <h1><a name="description">DESCRIPTION</a></h1>
54 <p>This module implements a client interface to the SMTP and ESMTP
55 protocol, enabling a perl5 application to talk to SMTP servers. This
56 documentation assumes that you are familiar with the concepts of the
57 SMTP protocol described in RFC821.</p>
58 <p>A new Net::SMTP object must be created with the <em>new</em> method. Once
59 this has been done, all SMTP commands are accessed through this object.</p>
60 <p>The Net::SMTP class is a subclass of Net::Cmd and IO::Socket::INET.</p>
61 <p>
62 </p>
63 <hr />
64 <h1><a name="examples">EXAMPLES</a></h1>
65 <p>This example prints the mail domain name of the SMTP server known as mailhost:</p>
66 <pre>
67 #!/usr/local/bin/perl -w</pre>
68 <pre>
69 use Net::SMTP;</pre>
70 <pre>
71 $smtp = Net::SMTP-&gt;new('mailhost');
72 print $smtp-&gt;domain,&quot;\n&quot;;
73 $smtp-&gt;quit;</pre>
74 <p>This example sends a small message to the postmaster at the SMTP server
75 known as mailhost:</p>
76 <pre>
77 #!/usr/local/bin/perl -w</pre>
78 <pre>
79 use Net::SMTP;</pre>
80 <pre>
81 $smtp = Net::SMTP-&gt;new('mailhost');</pre>
82 <pre>
83 $smtp-&gt;mail($ENV{USER});
84 $smtp-&gt;to('postmaster');</pre>
85 <pre>
86 $smtp-&gt;data();
87 $smtp-&gt;datasend(&quot;To: postmaster\n&quot;);
88 $smtp-&gt;datasend(&quot;\n&quot;);
89 $smtp-&gt;datasend(&quot;A simple test message\n&quot;);
90 $smtp-&gt;dataend();</pre>
91 <pre>
92 $smtp-&gt;quit;</pre>
93 <p>
94 </p>
95 <hr />
96 <h1><a name="constructor">CONSTRUCTOR</a></h1>
97 <dl>
98 <dt><strong><a name="item_new">new ( [ HOST ] [, OPTIONS ] )</a></strong>
100 <dd>
101 <p>This is the constructor for a new Net::SMTP object. <code>HOST</code> is the
102 name of the remote host to which an SMTP connection is required.</p>
103 </dd>
104 <dd>
105 <p><code>HOST</code> is optional. If <code>HOST</code> is not given then it may instead be
106 passed as the <code>Host</code> option described below. If neither is given then
107 the <code>SMTP_Hosts</code> specified in <code>Net::Config</code> will be used.</p>
108 </dd>
109 <dd>
110 <p><code>OPTIONS</code> are passed in a hash like fashion, using key and value pairs.
111 Possible options are:</p>
112 </dd>
113 <dd>
114 <p><strong>Hello</strong> - SMTP requires that you identify yourself. This option
115 specifies a string to pass as your mail domain. If not given localhost.localdomain
116 will be used.</p>
117 </dd>
118 <dd>
119 <p><strong>Host</strong> - SMTP host to connect to. It may be a single scalar, as defined for
120 the <code>PeerAddr</code> option in <a href="file://C|\msysgit\mingw\html/lib/IO/Socket/INET.html">the IO::Socket::INET manpage</a>, or a reference to
121 an array with hosts to try in turn. The <a href="#item_host">host</a> method will return the value
122 which was used to connect to the host.</p>
123 </dd>
124 <dd>
125 <p><strong>LocalAddr</strong> and <strong>LocalPort</strong> - These parameters are passed directly
126 to IO::Socket to allow binding the socket to a local port.</p>
127 </dd>
128 <dd>
129 <p><strong>Timeout</strong> - Maximum time, in seconds, to wait for a response from the
130 SMTP server (default: 120)</p>
131 </dd>
132 <dd>
133 <p><strong>ExactAddresses</strong> - If true the all ADDRESS arguments must be as
134 defined by <code>addr-spec</code> in RFC2822. If not given, or false, then
135 Net::SMTP will attempt to extract the address from the value passed.</p>
136 </dd>
137 <dd>
138 <p><strong>Debug</strong> - Enable debugging information</p>
139 </dd>
140 <dd>
141 <p>Example:</p>
142 </dd>
143 <dd>
144 <pre>
145 $smtp = Net::SMTP-&gt;new('mailhost',
146 Hello =&gt; 'my.mail.domain'
147 Timeout =&gt; 30,
148 Debug =&gt; 1,
149 );</pre>
150 </dd>
151 <dd>
152 <pre>
153 # the same
154 $smtp = Net::SMTP-&gt;new(
155 Host =&gt; 'mailhost',
156 Hello =&gt; 'my.mail.domain'
157 Timeout =&gt; 30,
158 Debug =&gt; 1,
159 );</pre>
160 </dd>
161 <dd>
162 <pre>
163 # Connect to the default server from Net::config
164 $smtp = Net::SMTP-&gt;new(
165 Hello =&gt; 'my.mail.domain'
166 Timeout =&gt; 30,
167 );</pre>
168 </dd>
169 </li>
170 </dl>
172 </p>
173 <hr />
174 <h1><a name="methods">METHODS</a></h1>
175 <p>Unless otherwise stated all methods return either a <em>true</em> or <em>false</em>
176 value, with <em>true</em> meaning that the operation was a success. When a method
177 states that it returns a value, failure will be returned as <em>undef</em> or an
178 empty list.</p>
179 <dl>
180 <dt><strong><a name="item_banner">banner ()</a></strong>
182 <dd>
183 <p>Returns the banner message which the server replied with when the
184 initial connection was made.</p>
185 </dd>
186 </li>
187 <dt><strong><a name="item_domain">domain ()</a></strong>
189 <dd>
190 <p>Returns the domain that the remote SMTP server identified itself as during
191 connection.</p>
192 </dd>
193 </li>
194 <dt><strong><a name="item_hello">hello ( DOMAIN )</a></strong>
196 <dd>
197 <p>Tell the remote server the mail domain which you are in using the EHLO
198 command (or HELO if EHLO fails). Since this method is invoked
199 automatically when the Net::SMTP object is constructed the user should
200 normally not have to call it manually.</p>
201 </dd>
202 </li>
203 <dt><strong><a name="item_host">host ()</a></strong>
205 <dd>
206 <p>Returns the value used by the constructor, and passed to IO::Socket::INET,
207 to connect to the host.</p>
208 </dd>
209 </li>
210 <dt><strong><a name="item_etrn">etrn ( DOMAIN )</a></strong>
212 <dd>
213 <p>Request a queue run for the DOMAIN given.</p>
214 </dd>
215 </li>
216 <dt><strong><a name="item_auth">auth ( USERNAME, PASSWORD )</a></strong>
218 <dd>
219 <p>Attempt SASL authentication.</p>
220 </dd>
221 </li>
222 <dt><strong><a name="item_mail">mail ( ADDRESS [, OPTIONS] )</a></strong>
224 <dt><strong><a name="item_send">send ( ADDRESS )</a></strong>
226 <dt><strong><a name="item_send_or_mail">send_or_mail ( ADDRESS )</a></strong>
228 <dt><strong><a name="item_send_and_mail">send_and_mail ( ADDRESS )</a></strong>
230 <dd>
231 <p>Send the appropriate command to the server MAIL, SEND, SOML or SAML. <code>ADDRESS</code>
232 is the address of the sender. This initiates the sending of a message. The
233 method <a href="#item_recipient"><code>recipient</code></a> should be called for each address that the message is to
234 be sent to.</p>
235 </dd>
236 <dd>
237 <p>The <a href="#item_mail"><code>mail</code></a> method can some additional ESMTP OPTIONS which is passed
238 in hash like fashion, using key and value pairs. Possible options are:</p>
239 </dd>
240 <dd>
241 <pre>
242 Size =&gt; &lt;bytes&gt;
243 Return =&gt; &quot;FULL&quot; | &quot;HDRS&quot;
244 Bits =&gt; &quot;7&quot; | &quot;8&quot; | &quot;binary&quot;
245 Transaction =&gt; &lt;ADDRESS&gt;
246 Envelope =&gt; &lt;ENVID&gt;
247 XVERP =&gt; 1</pre>
248 </dd>
249 <dd>
250 <p>The <code>Return</code> and <code>Envelope</code> parameters are used for DSN (Delivery
251 Status Notification).</p>
252 </dd>
253 </li>
254 <dt><strong><a name="item_reset">reset ()</a></strong>
256 <dd>
257 <p>Reset the status of the server. This may be called after a message has been
258 initiated, but before any data has been sent, to cancel the sending of the
259 message.</p>
260 </dd>
261 </li>
262 <dt><strong><a name="item_recipient">recipient ( ADDRESS [, ADDRESS, [...]] [, OPTIONS ] )</a></strong>
264 <dd>
265 <p>Notify the server that the current message should be sent to all of the
266 addresses given. Each address is sent as a separate command to the server.
267 Should the sending of any address result in a failure then the process is
268 aborted and a <em>false</em> value is returned. It is up to the user to call
269 <a href="#item_reset"><code>reset</code></a> if they so desire.</p>
270 </dd>
271 <dd>
272 <p>The <a href="#item_recipient"><code>recipient</code></a> method can also pass additional case-sensitive OPTIONS as an
273 anonymous hash using key and value pairs. Possible options are:</p>
274 </dd>
275 <dd>
276 <pre>
277 Notify =&gt; ['NEVER'] or ['SUCCESS','FAILURE','DELAY'] (see below)
278 SkipBad =&gt; 1 (to ignore bad addresses)</pre>
279 </dd>
280 <dd>
281 <p>If <code>SkipBad</code> is true the <a href="#item_recipient"><code>recipient</code></a> will not return an error when a bad
282 address is encountered and it will return an array of addresses that did
283 succeed.</p>
284 </dd>
285 <dd>
286 <pre>
287 $smtp-&gt;recipient($recipient1,$recipient2); # Good
288 $smtp-&gt;recipient($recipient1,$recipient2, { SkipBad =&gt; 1 }); # Good
289 $smtp-&gt;recipient($recipient1,$recipient2, { Notify =&gt; ['FAILURE','DELAY'], SkipBad =&gt; 1 }); # Good
290 @goodrecips=$smtp-&gt;recipient(@recipients, { Notify =&gt; ['FAILURE'], SkipBad =&gt; 1 }); # Good
291 $smtp-&gt;recipient(&quot;$recipient,$recipient2&quot;); # BAD</pre>
292 </dd>
293 <dd>
294 <p>Notify is used to request Delivery Status Notifications (DSNs), but your
295 SMTP/ESMTP service may not respect this request depending upon its version and
296 your site's SMTP configuration.</p>
297 </dd>
298 <dd>
299 <p>Leaving out the Notify option usually defaults an SMTP service to its default
300 behavior equivalent to ['FAILURE'] notifications only, but again this may be
301 dependent upon your site's SMTP configuration.</p>
302 </dd>
303 <dd>
304 <p>The NEVER keyword must appear by itself if used within the Notify option and ``requests
305 that a DSN not be returned to the sender under any conditions.''</p>
306 </dd>
307 <dd>
308 <pre>
309 {Notify =&gt; ['NEVER']}</pre>
310 </dd>
311 <dd>
312 <pre>
313 $smtp-&gt;recipient(@recipients, { Notify =&gt; ['NEVER'], SkipBad =&gt; 1 }); # Good</pre>
314 </dd>
315 <dd>
316 <p>You may use any combination of these three values 'SUCCESS','FAILURE','DELAY' in
317 the anonymous array reference as defined by RFC3461 (see <a href="http://rfc.net/rfc3461.html">http://rfc.net/rfc3461.html</a>
318 for more information. Note: quotations in this topic from same.).</p>
319 </dd>
320 <dd>
321 <p>A Notify parameter of 'SUCCESS' or 'FAILURE' ``requests that a DSN be issued on
322 successful delivery or delivery failure, respectively.''</p>
323 </dd>
324 <dd>
325 <p>A Notify parameter of 'DELAY' ``indicates the sender's willingness to receive
326 delayed DSNs. Delayed DSNs may be issued if delivery of a message has been
327 delayed for an unusual amount of time (as determined by the Message Transfer
328 Agent (MTA) at which the message is delayed), but the final delivery status
329 (whether successful or failure) cannot be determined. The absence of the DELAY
330 keyword in a NOTIFY parameter requests that a ''delayed`` DSN NOT be issued under
331 any conditions.''</p>
332 </dd>
333 <dd>
334 <pre>
335 {Notify =&gt; ['SUCCESS','FAILURE','DELAY']}</pre>
336 </dd>
337 <dd>
338 <pre>
339 $smtp-&gt;recipient(@recipients, { Notify =&gt; ['FAILURE','DELAY'], SkipBad =&gt; 1 }); # Good</pre>
340 </dd>
341 </li>
342 <dt><strong><a name="item_to">to ( ADDRESS [, ADDRESS [...]] )</a></strong>
344 <dt><strong><a name="item_cc">cc ( ADDRESS [, ADDRESS [...]] )</a></strong>
346 <dt><strong><a name="item_bcc">bcc ( ADDRESS [, ADDRESS [...]] )</a></strong>
348 <dd>
349 <p>Synonyms for <a href="#item_recipient"><code>recipient</code></a>.</p>
350 </dd>
351 </li>
352 <dt><strong><a name="item_data">data ( [ DATA ] )</a></strong>
354 <dd>
355 <p>Initiate the sending of the data from the current message.</p>
356 </dd>
357 <dd>
358 <p><code>DATA</code> may be a reference to a list or a list. If specified the contents
359 of <code>DATA</code> and a termination string <code>&quot;.\r\n&quot;</code> is sent to the server. And the
360 result will be true if the data was accepted.</p>
361 </dd>
362 <dd>
363 <p>If <code>DATA</code> is not specified then the result will indicate that the server
364 wishes the data to be sent. The data must then be sent using the <code>datasend</code>
365 and <code>dataend</code> methods described in <a href="file://C|\msysgit\mingw\html/lib/Net/Cmd.html">the Net::Cmd manpage</a>.</p>
366 </dd>
367 </li>
368 <dt><strong><a name="item_expand">expand ( ADDRESS )</a></strong>
370 <dd>
371 <p>Request the server to expand the given address Returns an array
372 which contains the text read from the server.</p>
373 </dd>
374 </li>
375 <dt><strong><a name="item_verify">verify ( ADDRESS )</a></strong>
377 <dd>
378 <p>Verify that <code>ADDRESS</code> is a legitimate mailing address.</p>
379 </dd>
380 <dd>
381 <p>Most sites usually disable this feature in their SMTP service configuration.
382 Use ``Debug =&gt; 1'' option under <a href="#item_new"><code>new()</code></a> to see if disabled.</p>
383 </dd>
384 </li>
385 <dt><strong><a name="item_help">help ( [ $subject ] )</a></strong>
387 <dd>
388 <p>Request help text from the server. Returns the text or undef upon failure</p>
389 </dd>
390 </li>
391 <dt><strong><a name="item_quit">quit ()</a></strong>
393 <dd>
394 <p>Send the QUIT command to the remote SMTP server and close the socket connection.</p>
395 </dd>
396 </li>
397 </dl>
399 </p>
400 <hr />
401 <h1><a name="addresses">ADDRESSES</a></h1>
402 <p>Net::SMTP attempts to DWIM with addresses that are passed. For
403 example an application might extract The From: line from an email
404 and pass that to mail(). While this may work, it is not reccomended.
405 The application should really use a module like <a href="file://C|\msysgit\mingw\html/Mail/Address.html">the Mail::Address manpage</a>
406 to extract the mail address and pass that.</p>
407 <p>If <code>ExactAddresses</code> is passed to the contructor, then addresses
408 should be a valid rfc2821-quoted address, although Net::SMTP will
409 accept accept the address surrounded by angle brackets.</p>
410 <pre>
411 funny user@domain WRONG
412 &quot;funny user&quot;@domain RIGHT, recommended
413 &lt;&quot;funny user&quot;@domain&gt; OK</pre>
415 </p>
416 <hr />
417 <h1><a name="see_also">SEE ALSO</a></h1>
418 <p><a href="file://C|\msysgit\mingw\html/lib/Net/Cmd.html">the Net::Cmd manpage</a></p>
420 </p>
421 <hr />
422 <h1><a name="author">AUTHOR</a></h1>
423 <p>Graham Barr &lt;<a href="mailto:gbarr@pobox.com">gbarr@pobox.com</a>&gt;</p>
425 </p>
426 <hr />
427 <h1><a name="copyright">COPYRIGHT</a></h1>
428 <p>Copyright (c) 1995-2004 Graham Barr. All rights reserved.
429 This program is free software; you can redistribute it and/or modify
430 it under the same terms as Perl itself.</p>
431 <table border="0" width="100%" cellspacing="0" cellpadding="3">
432 <tr><td class="block" style="background-color: #cccccc" valign="middle">
433 <big><strong><span class="block">&nbsp;Net::SMTP - Simple Mail Transfer Protocol Client</span></strong></big>
434 </td></tr>
435 </table>
437 </body>
439 </html>