Version change to ExtUtils::MM_Unix missed in change #30380.
[p5sagit/p5-mst-13.2.git] / lib / Net / SMTP.pm
CommitLineData
406c51ee 1# Net::SMTP.pm
2#
f92f3fcb 3# Copyright (c) 1995-2004 Graham Barr <gbarr@pobox.com>. All rights reserved.
406c51ee 4# This program is free software; you can redistribute it and/or
5# modify it under the same terms as Perl itself.
6
7package Net::SMTP;
8
9require 5.001;
10
11use strict;
12use vars qw($VERSION @ISA);
13use Socket 1.3;
14use Carp;
15use IO::Socket;
16use Net::Cmd;
17use Net::Config;
18
7cf5cf7c 19$VERSION = "2.30";
406c51ee 20
21@ISA = qw(Net::Cmd IO::Socket::INET);
22
23sub new
24{
25 my $self = shift;
26 my $type = ref($self) || $self;
f92f3fcb 27 my ($host,%arg);
28 if (@_ % 2) {
29 $host = shift ;
30 %arg = @_;
31 } else {
32 %arg = @_;
33 $host=delete $arg{Host};
34 }
dea4d7df 35 my $hosts = defined $host ? $host : $NetConfig{smtp_hosts};
406c51ee 36 my $obj;
37
38 my $h;
dea4d7df 39 foreach $h (@{ref($hosts) ? $hosts : [ $hosts ]})
406c51ee 40 {
41 $obj = $type->SUPER::new(PeerAddr => ($host = $h),
42 PeerPort => $arg{Port} || 'smtp(25)',
12df23ee 43 LocalAddr => $arg{LocalAddr},
44 LocalPort => $arg{LocalPort},
406c51ee 45 Proto => 'tcp',
46 Timeout => defined $arg{Timeout}
47 ? $arg{Timeout}
48 : 120
49 ) and last;
50 }
51
52 return undef
53 unless defined $obj;
54
55 $obj->autoflush(1);
56
57 $obj->debug(exists $arg{Debug} ? $arg{Debug} : undef);
58
59 unless ($obj->response() == CMD_OK)
60 {
61 $obj->close();
62 return undef;
63 }
64
dea4d7df 65 ${*$obj}{'net_smtp_exact_addr'} = $arg{ExactAddresses};
406c51ee 66 ${*$obj}{'net_smtp_host'} = $host;
67
68 (${*$obj}{'net_smtp_banner'}) = $obj->message;
69 (${*$obj}{'net_smtp_domain'}) = $obj->message =~ /\A\s*(\S+)/;
70
71 unless($obj->hello($arg{Hello} || ""))
72 {
73 $obj->close();
74 return undef;
75 }
76
77 $obj;
78}
79
f92f3fcb 80sub host {
81 my $me = shift;
82 ${*$me}{'net_smtp_host'};
83}
84
406c51ee 85##
86## User interface methods
87##
88
89sub banner
90{
91 my $me = shift;
92
93 return ${*$me}{'net_smtp_banner'} || undef;
94}
95
96sub domain
97{
98 my $me = shift;
99
100 return ${*$me}{'net_smtp_domain'} || undef;
101}
102
103sub etrn {
104 my $self = shift;
105 defined($self->supports('ETRN',500,["Command unknown: 'ETRN'"])) &&
106 $self->_ETRN(@_);
107}
108
16f7bb68 109sub auth {
110 my ($self, $username, $password) = @_;
c8570720 111
9714c667 112 eval {
113 require MIME::Base64;
114 require Authen::SASL;
115 } or $self->set_status(500,["Need MIME::Base64 and Authen::SASL todo auth"]), return 0;
c8570720 116
117 my $mechanisms = $self->supports('AUTH',500,["Command unknown: 'AUTH'"]);
118 return unless defined $mechanisms;
119
16f7bb68 120 my $sasl;
121
122 if (ref($username) and UNIVERSAL::isa($username,'Authen::SASL')) {
123 $sasl = $username;
124 $sasl->mechanism($mechanisms);
125 }
126 else {
127 die "auth(username, password)" if not length $username;
128 $sasl = Authen::SASL->new(mechanism=> $mechanisms,
129 callback => { user => $username,
130 pass => $password,
131 authname => $username,
132 });
133 }
134
135 # We should probably allow the user to pass the host, but I don't
136 # currently know and SASL mechanisms that are used by smtp that need it
137 my $client = $sasl->client_new('smtp',${*$self}{'net_smtp_host'},0);
138 my $str = $client->client_start;
139 # We dont support sasl mechanisms that encrypt the socket traffic.
140 # todo that we would really need to change the ISA hierarchy
141 # so we dont inherit from IO::Socket, but instead hold it in an attribute
142
edd55068 143 my @cmd = ("AUTH", $client->mechanism);
16f7bb68 144 my $code;
145
edd55068 146 push @cmd, MIME::Base64::encode_base64($str,'')
147 if defined $str and length $str;
148
16f7bb68 149 while (($code = $self->command(@cmd)->response()) == CMD_MORE) {
150 @cmd = (MIME::Base64::encode_base64(
151 $client->client_step(
152 MIME::Base64::decode_base64(
153 ($self->message)[0]
154 )
155 ), ''
156 ));
c8570720 157 }
c8570720 158
16f7bb68 159 $code == CMD_OK;
c8570720 160}
161
406c51ee 162sub hello
163{
164 my $me = shift;
046d9f47 165 my $domain = shift || "localhost.localdomain";
406c51ee 166 my $ok = $me->_EHLO($domain);
167 my @msg = $me->message;
168
169 if($ok)
170 {
171 my $h = ${*$me}{'net_smtp_esmtp'} = {};
172 my $ln;
173 foreach $ln (@msg) {
686337f3 174 $h->{uc $1} = $2
67ada6d4 175 if $ln =~ /(\w+)\b[= \t]*([^\n]*)/;
406c51ee 176 }
177 }
178 elsif($me->status == CMD_ERROR)
179 {
180 @msg = $me->message
181 if $ok = $me->_HELO($domain);
182 }
183
dea4d7df 184 return undef unless $ok;
185
186 $msg[0] =~ /\A\s*(\S+)/;
187 return ($1 || " ");
406c51ee 188}
189
190sub supports {
191 my $self = shift;
192 my $cmd = uc shift;
193 return ${*$self}{'net_smtp_esmtp'}->{$cmd}
194 if exists ${*$self}{'net_smtp_esmtp'}->{$cmd};
195 $self->set_status(@_)
196 if @_;
197 return;
198}
199
16f7bb68 200sub _addr {
dea4d7df 201 my $self = shift;
16f7bb68 202 my $addr = shift;
203 $addr = "" unless defined $addr;
dea4d7df 204
205 if (${*$self}{'net_smtp_exact_addr'}) {
206 return $1 if $addr =~ /^\s*(<.*>)\s*$/s;
207 }
208 else {
209 return $1 if $addr =~ /(<[^>]*>)/;
210 $addr =~ s/^\s+|\s+$//sg;
211 }
212
16f7bb68 213 "<$addr>";
406c51ee 214}
215
406c51ee 216sub mail
217{
218 my $me = shift;
dea4d7df 219 my $addr = _addr($me, shift);
406c51ee 220 my $opts = "";
221
222 if(@_)
223 {
224 my %opt = @_;
225 my($k,$v);
226
227 if(exists ${*$me}{'net_smtp_esmtp'})
228 {
229 my $esmtp = ${*$me}{'net_smtp_esmtp'};
230
231 if(defined($v = delete $opt{Size}))
232 {
233 if(exists $esmtp->{SIZE})
234 {
235 $opts .= sprintf " SIZE=%d", $v + 0
236 }
237 else
238 {
239 carp 'Net::SMTP::mail: SIZE option not supported by host';
240 }
241 }
242
243 if(defined($v = delete $opt{Return}))
244 {
245 if(exists $esmtp->{DSN})
246 {
dea4d7df 247 $opts .= " RET=" . ((uc($v) eq "FULL") ? "FULL" : "HDRS");
406c51ee 248 }
249 else
250 {
251 carp 'Net::SMTP::mail: DSN option not supported by host';
252 }
253 }
254
255 if(defined($v = delete $opt{Bits}))
256 {
dea4d7df 257 if($v eq "8")
258 {
259 if(exists $esmtp->{'8BITMIME'})
260 {
261 $opts .= " BODY=8BITMIME";
262 }
263 else
264 {
265 carp 'Net::SMTP::mail: 8BITMIME option not supported by host';
266 }
267 }
268 elsif($v eq "binary")
269 {
270 if(exists $esmtp->{'BINARYMIME'} && exists $esmtp->{'CHUNKING'})
271 {
272 $opts .= " BODY=BINARYMIME";
273 ${*$me}{'net_smtp_chunking'} = 1;
274 }
275 else
276 {
277 carp 'Net::SMTP::mail: BINARYMIME option not supported by host';
278 }
279 }
280 elsif(exists $esmtp->{'8BITMIME'} or exists $esmtp->{'BINARYMIME'})
406c51ee 281 {
dea4d7df 282 $opts .= " BODY=7BIT";
406c51ee 283 }
284 else
285 {
dea4d7df 286 carp 'Net::SMTP::mail: 8BITMIME and BINARYMIME options not supported by host';
406c51ee 287 }
288 }
289
290 if(defined($v = delete $opt{Transaction}))
291 {
292 if(exists $esmtp->{CHECKPOINT})
293 {
dea4d7df 294 $opts .= " TRANSID=" . _addr($me, $v);
406c51ee 295 }
296 else
297 {
298 carp 'Net::SMTP::mail: CHECKPOINT option not supported by host';
299 }
300 }
301
302 if(defined($v = delete $opt{Envelope}))
303 {
304 if(exists $esmtp->{DSN})
305 {
306 $v =~ s/([^\041-\176]|=|\+)/sprintf "+%02x", ord($1)/sge;
307 $opts .= " ENVID=$v"
308 }
309 else
310 {
311 carp 'Net::SMTP::mail: DSN option not supported by host';
312 }
313 }
314
f92f3fcb 315 if(defined($v = delete $opt{XVERP}))
316 {
317 if(exists $esmtp->{'XVERP'})
318 {
319 $opts .= " XVERP"
320 }
321 else
322 {
323 carp 'Net::SMTP::mail: XVERP option not supported by host';
324 }
325 }
326
406c51ee 327 carp 'Net::SMTP::recipient: unknown option(s) '
328 . join(" ", keys %opt)
329 . ' - ignored'
330 if scalar keys %opt;
331 }
332 else
333 {
334 carp 'Net::SMTP::mail: ESMTP not supported by host - options discarded :-(';
335 }
336 }
337
338 $me->_MAIL("FROM:".$addr.$opts);
339}
340
dea4d7df 341sub send { my $me = shift; $me->_SEND("FROM:" . _addr($me, $_[0])) }
342sub send_or_mail { my $me = shift; $me->_SOML("FROM:" . _addr($me, $_[0])) }
343sub send_and_mail { my $me = shift; $me->_SAML("FROM:" . _addr($me, $_[0])) }
406c51ee 344
345sub reset
346{
347 my $me = shift;
348
349 $me->dataend()
350 if(exists ${*$me}{'net_smtp_lastch'});
351
352 $me->_RSET();
353}
354
355
356sub recipient
357{
358 my $smtp = shift;
359 my $opts = "";
360 my $skip_bad = 0;
361
362 if(@_ && ref($_[-1]))
363 {
364 my %opt = %{pop(@_)};
365 my $v;
366
367 $skip_bad = delete $opt{'SkipBad'};
368
369 if(exists ${*$smtp}{'net_smtp_esmtp'})
370 {
371 my $esmtp = ${*$smtp}{'net_smtp_esmtp'};
372
373 if(defined($v = delete $opt{Notify}))
374 {
375 if(exists $esmtp->{DSN})
376 {
377 $opts .= " NOTIFY=" . join(",",map { uc $_ } @$v)
378 }
379 else
380 {
381 carp 'Net::SMTP::recipient: DSN option not supported by host';
382 }
383 }
384
7cf5cf7c 385 if(defined($v = delete $opt{ORcpt}))
386 {
387 if(exists $esmtp->{DSN})
388 {
389 $opts .= " ORCPT=" . $v;
390 }
391 else
392 {
393 carp 'Net::SMTP::recipient: DSN option not supported by host';
394 }
395 }
396
406c51ee 397 carp 'Net::SMTP::recipient: unknown option(s) '
398 . join(" ", keys %opt)
399 . ' - ignored'
400 if scalar keys %opt;
401 }
402 elsif(%opt)
403 {
404 carp 'Net::SMTP::recipient: ESMTP not supported by host - options discarded :-(';
405 }
406 }
407
408 my @ok;
409 my $addr;
410 foreach $addr (@_)
411 {
dea4d7df 412 if($smtp->_RCPT("TO:" . _addr($smtp, $addr) . $opts)) {
406c51ee 413 push(@ok,$addr) if $skip_bad;
414 }
415 elsif(!$skip_bad) {
416 return 0;
417 }
418 }
419
420 return $skip_bad ? @ok : 1;
421}
422
686337f3 423BEGIN {
424 *to = \&recipient;
425 *cc = \&recipient;
426 *bcc = \&recipient;
427}
406c51ee 428
429sub data
430{
431 my $me = shift;
432
dea4d7df 433 if(exists ${*$me}{'net_smtp_chunking'})
434 {
435 carp 'Net::SMTP::data: CHUNKING extension in use, must call bdat instead';
436 }
437 else
438 {
439 my $ok = $me->_DATA() && $me->datasend(@_);
440
441 $ok && @_ ? $me->dataend
442 : $ok;
443 }
444}
445
446sub bdat
447{
448 my $me = shift;
449
450 if(exists ${*$me}{'net_smtp_chunking'})
451 {
452 my $data = shift;
406c51ee 453
dea4d7df 454 $me->_BDAT(length $data) && $me->rawdatasend($data) &&
455 $me->response() == CMD_OK;
456 }
457 else
458 {
459 carp 'Net::SMTP::bdat: CHUNKING extension is not in use, call data instead';
460 }
461}
462
463sub bdatlast
464{
465 my $me = shift;
466
467 if(exists ${*$me}{'net_smtp_chunking'})
468 {
469 my $data = shift;
470
471 $me->_BDAT(length $data, "LAST") && $me->rawdatasend($data) &&
472 $me->response() == CMD_OK;
473 }
474 else
475 {
476 carp 'Net::SMTP::bdat: CHUNKING extension is not in use, call data instead';
477 }
406c51ee 478}
479
12df23ee 480sub datafh {
481 my $me = shift;
482 return unless $me->_DATA();
483 return $me->tied_fh;
484}
485
406c51ee 486sub expand
487{
488 my $me = shift;
489
490 $me->_EXPN(@_) ? ($me->message)
491 : ();
492}
493
494
495sub verify { shift->_VRFY(@_) }
496
497sub help
498{
499 my $me = shift;
500
501 $me->_HELP(@_) ? scalar $me->message
502 : undef;
503}
504
505sub quit
506{
507 my $me = shift;
508
509 $me->_QUIT;
510 $me->close;
511}
512
513sub DESTROY
514{
515# ignore
516}
517
518##
519## RFC821 commands
520##
521
522sub _EHLO { shift->command("EHLO", @_)->response() == CMD_OK }
523sub _HELO { shift->command("HELO", @_)->response() == CMD_OK }
524sub _MAIL { shift->command("MAIL", @_)->response() == CMD_OK }
525sub _RCPT { shift->command("RCPT", @_)->response() == CMD_OK }
526sub _SEND { shift->command("SEND", @_)->response() == CMD_OK }
527sub _SAML { shift->command("SAML", @_)->response() == CMD_OK }
528sub _SOML { shift->command("SOML", @_)->response() == CMD_OK }
529sub _VRFY { shift->command("VRFY", @_)->response() == CMD_OK }
530sub _EXPN { shift->command("EXPN", @_)->response() == CMD_OK }
531sub _HELP { shift->command("HELP", @_)->response() == CMD_OK }
532sub _RSET { shift->command("RSET")->response() == CMD_OK }
533sub _NOOP { shift->command("NOOP")->response() == CMD_OK }
534sub _QUIT { shift->command("QUIT")->response() == CMD_OK }
535sub _DATA { shift->command("DATA")->response() == CMD_MORE }
dea4d7df 536sub _BDAT { shift->command("BDAT", @_) }
406c51ee 537sub _TURN { shift->unsupported(@_); }
538sub _ETRN { shift->command("ETRN", @_)->response() == CMD_OK }
c8570720 539sub _AUTH { shift->command("AUTH", @_)->response() == CMD_OK }
406c51ee 540
5411;
542
543__END__
544
545=head1 NAME
546
547Net::SMTP - Simple Mail Transfer Protocol Client
548
549=head1 SYNOPSIS
550
551 use Net::SMTP;
686337f3 552
406c51ee 553 # Constructors
554 $smtp = Net::SMTP->new('mailhost');
555 $smtp = Net::SMTP->new('mailhost', Timeout => 60);
556
557=head1 DESCRIPTION
558
559This module implements a client interface to the SMTP and ESMTP
560protocol, enabling a perl5 application to talk to SMTP servers. This
561documentation assumes that you are familiar with the concepts of the
562SMTP protocol described in RFC821.
563
564A new Net::SMTP object must be created with the I<new> method. Once
565this has been done, all SMTP commands are accessed through this object.
566
567The Net::SMTP class is a subclass of Net::Cmd and IO::Socket::INET.
568
569=head1 EXAMPLES
570
571This example prints the mail domain name of the SMTP server known as mailhost:
572
573 #!/usr/local/bin/perl -w
686337f3 574
406c51ee 575 use Net::SMTP;
686337f3 576
406c51ee 577 $smtp = Net::SMTP->new('mailhost');
578 print $smtp->domain,"\n";
579 $smtp->quit;
580
581This example sends a small message to the postmaster at the SMTP server
582known as mailhost:
583
584 #!/usr/local/bin/perl -w
686337f3 585
406c51ee 586 use Net::SMTP;
686337f3 587
406c51ee 588 $smtp = Net::SMTP->new('mailhost');
686337f3 589
406c51ee 590 $smtp->mail($ENV{USER});
591 $smtp->to('postmaster');
686337f3 592
406c51ee 593 $smtp->data();
594 $smtp->datasend("To: postmaster\n");
595 $smtp->datasend("\n");
596 $smtp->datasend("A simple test message\n");
597 $smtp->dataend();
686337f3 598
406c51ee 599 $smtp->quit;
600
601=head1 CONSTRUCTOR
602
603=over 4
604
f92f3fcb 605=item new ( [ HOST ] [, OPTIONS ] )
406c51ee 606
607This is the constructor for a new Net::SMTP object. C<HOST> is the
d1be9408 608name of the remote host to which an SMTP connection is required.
406c51ee 609
f92f3fcb 610C<HOST> is optional. If C<HOST> is not given then it may instead be
611passed as the C<Host> option described below. If neither is given then
612the C<SMTP_Hosts> specified in C<Net::Config> will be used.
406c51ee 613
614C<OPTIONS> are passed in a hash like fashion, using key and value pairs.
615Possible options are:
616
617B<Hello> - SMTP requires that you identify yourself. This option
f92f3fcb 618specifies a string to pass as your mail domain. If not given localhost.localdomain
619will be used.
620
621B<Host> - SMTP host to connect to. It may be a single scalar, as defined for
622the C<PeerAddr> option in L<IO::Socket::INET>, or a reference to
623an array with hosts to try in turn. The L</host> method will return the value
624which was used to connect to the host.
406c51ee 625
12df23ee 626B<LocalAddr> and B<LocalPort> - These parameters are passed directly
627to IO::Socket to allow binding the socket to a local port.
628
406c51ee 629B<Timeout> - Maximum time, in seconds, to wait for a response from the
630SMTP server (default: 120)
631
dea4d7df 632B<ExactAddresses> - If true the all ADDRESS arguments must be as
633defined by C<addr-spec> in RFC2822. If not given, or false, then
634Net::SMTP will attempt to extract the address from the value passed.
635
406c51ee 636B<Debug> - Enable debugging information
637
638
639Example:
640
641
642 $smtp = Net::SMTP->new('mailhost',
7cf5cf7c 643 Hello => 'my.mail.domain',
406c51ee 644 Timeout => 30,
645 Debug => 1,
646 );
647
f92f3fcb 648 # the same
649 $smtp = Net::SMTP->new(
650 Host => 'mailhost',
7cf5cf7c 651 Hello => 'my.mail.domain',
f92f3fcb 652 Timeout => 30,
653 Debug => 1,
654 );
655
656 # Connect to the default server from Net::config
657 $smtp = Net::SMTP->new(
7cf5cf7c 658 Hello => 'my.mail.domain',
f92f3fcb 659 Timeout => 30,
660 );
661
686337f3 662=back
663
406c51ee 664=head1 METHODS
665
666Unless otherwise stated all methods return either a I<true> or I<false>
667value, with I<true> meaning that the operation was a success. When a method
668states that it returns a value, failure will be returned as I<undef> or an
669empty list.
670
671=over 4
672
673=item banner ()
674
675Returns the banner message which the server replied with when the
676initial connection was made.
677
678=item domain ()
679
680Returns the domain that the remote SMTP server identified itself as during
681connection.
682
683=item hello ( DOMAIN )
684
685Tell the remote server the mail domain which you are in using the EHLO
686command (or HELO if EHLO fails). Since this method is invoked
687automatically when the Net::SMTP object is constructed the user should
688normally not have to call it manually.
689
f92f3fcb 690=item host ()
691
692Returns the value used by the constructor, and passed to IO::Socket::INET,
693to connect to the host.
694
406c51ee 695=item etrn ( DOMAIN )
696
697Request a queue run for the DOMAIN given.
698
c8570720 699=item auth ( USERNAME, PASSWORD )
700
16f7bb68 701Attempt SASL authentication.
c8570720 702
406c51ee 703=item mail ( ADDRESS [, OPTIONS] )
704
705=item send ( ADDRESS )
706
707=item send_or_mail ( ADDRESS )
708
709=item send_and_mail ( ADDRESS )
710
711Send the appropriate command to the server MAIL, SEND, SOML or SAML. C<ADDRESS>
712is the address of the sender. This initiates the sending of a message. The
713method C<recipient> should be called for each address that the message is to
714be sent to.
715
716The C<mail> method can some additional ESMTP OPTIONS which is passed
717in hash like fashion, using key and value pairs. Possible options are:
718
719 Size => <bytes>
dea4d7df 720 Return => "FULL" | "HDRS"
721 Bits => "7" | "8" | "binary"
406c51ee 722 Transaction => <ADDRESS>
723 Envelope => <ENVID>
f92f3fcb 724 XVERP => 1
406c51ee 725
dea4d7df 726The C<Return> and C<Envelope> parameters are used for DSN (Delivery
727Status Notification).
406c51ee 728
729=item reset ()
730
731Reset the status of the server. This may be called after a message has been
732initiated, but before any data has been sent, to cancel the sending of the
733message.
734
f92f3fcb 735=item recipient ( ADDRESS [, ADDRESS, [...]] [, OPTIONS ] )
406c51ee 736
737Notify the server that the current message should be sent to all of the
738addresses given. Each address is sent as a separate command to the server.
f92f3fcb 739Should the sending of any address result in a failure then the process is
740aborted and a I<false> value is returned. It is up to the user to call
741C<reset> if they so desire.
406c51ee 742
f92f3fcb 743The C<recipient> method can also pass additional case-sensitive OPTIONS as an
744anonymous hash using key and value pairs. Possible options are:
406c51ee 745
f92f3fcb 746 Notify => ['NEVER'] or ['SUCCESS','FAILURE','DELAY'] (see below)
7cf5cf7c 747 ORcpt => <ORCPT>
f92f3fcb 748 SkipBad => 1 (to ignore bad addresses)
406c51ee 749
f92f3fcb 750If C<SkipBad> is true the C<recipient> will not return an error when a bad
751address is encountered and it will return an array of addresses that did
752succeed.
406c51ee 753
686337f3 754 $smtp->recipient($recipient1,$recipient2); # Good
755 $smtp->recipient($recipient1,$recipient2, { SkipBad => 1 }); # Good
f92f3fcb 756 $smtp->recipient($recipient1,$recipient2, { Notify => ['FAILURE','DELAY'], SkipBad => 1 }); # Good
757 @goodrecips=$smtp->recipient(@recipients, { Notify => ['FAILURE'], SkipBad => 1 }); # Good
758 $smtp->recipient("$recipient,$recipient2"); # BAD
759
760Notify is used to request Delivery Status Notifications (DSNs), but your
761SMTP/ESMTP service may not respect this request depending upon its version and
762your site's SMTP configuration.
763
764Leaving out the Notify option usually defaults an SMTP service to its default
765behavior equivalent to ['FAILURE'] notifications only, but again this may be
766dependent upon your site's SMTP configuration.
767
768The NEVER keyword must appear by itself if used within the Notify option and "requests
769that a DSN not be returned to the sender under any conditions."
770
771 {Notify => ['NEVER']}
772
773 $smtp->recipient(@recipients, { Notify => ['NEVER'], SkipBad => 1 }); # Good
774
775You may use any combination of these three values 'SUCCESS','FAILURE','DELAY' in
776the anonymous array reference as defined by RFC3461 (see http://rfc.net/rfc3461.html
777for more information. Note: quotations in this topic from same.).
778
779A Notify parameter of 'SUCCESS' or 'FAILURE' "requests that a DSN be issued on
780successful delivery or delivery failure, respectively."
781
782A Notify parameter of 'DELAY' "indicates the sender's willingness to receive
783delayed DSNs. Delayed DSNs may be issued if delivery of a message has been
784delayed for an unusual amount of time (as determined by the Message Transfer
785Agent (MTA) at which the message is delayed), but the final delivery status
786(whether successful or failure) cannot be determined. The absence of the DELAY
787keyword in a NOTIFY parameter requests that a "delayed" DSN NOT be issued under
788any conditions."
789
790 {Notify => ['SUCCESS','FAILURE','DELAY']}
791
792 $smtp->recipient(@recipients, { Notify => ['FAILURE','DELAY'], SkipBad => 1 }); # Good
686337f3 793
7cf5cf7c 794ORcpt is also part of the SMTP DSN extension according to RFC3461.
795It is used to pass along the original recipient that the mail was first
796sent to. The machine that generates a DSN will use this address to inform
797the sender, because he can't know if recipients get rewritten by mail servers.
798
406c51ee 799=item to ( ADDRESS [, ADDRESS [...]] )
800
686337f3 801=item cc ( ADDRESS [, ADDRESS [...]] )
802
803=item bcc ( ADDRESS [, ADDRESS [...]] )
804
805Synonyms for C<recipient>.
406c51ee 806
807=item data ( [ DATA ] )
808
809Initiate the sending of the data from the current message.
810
811C<DATA> may be a reference to a list or a list. If specified the contents
812of C<DATA> and a termination string C<".\r\n"> is sent to the server. And the
813result will be true if the data was accepted.
814
815If C<DATA> is not specified then the result will indicate that the server
816wishes the data to be sent. The data must then be sent using the C<datasend>
817and C<dataend> methods described in L<Net::Cmd>.
818
819=item expand ( ADDRESS )
820
821Request the server to expand the given address Returns an array
822which contains the text read from the server.
823
824=item verify ( ADDRESS )
825
826Verify that C<ADDRESS> is a legitimate mailing address.
827
f92f3fcb 828Most sites usually disable this feature in their SMTP service configuration.
829Use "Debug => 1" option under new() to see if disabled.
830
406c51ee 831=item help ( [ $subject ] )
832
833Request help text from the server. Returns the text or undef upon failure
834
835=item quit ()
836
837Send the QUIT command to the remote SMTP server and close the socket connection.
838
839=back
840
16f7bb68 841=head1 ADDRESSES
842
dea4d7df 843Net::SMTP attempts to DWIM with addresses that are passed. For
844example an application might extract The From: line from an email
3c4b39be 845and pass that to mail(). While this may work, it is not recommended.
dea4d7df 846The application should really use a module like L<Mail::Address>
847to extract the mail address and pass that.
848
3c4b39be 849If C<ExactAddresses> is passed to the constructor, then addresses
dea4d7df 850should be a valid rfc2821-quoted address, although Net::SMTP will
851accept accept the address surrounded by angle brackets.
16f7bb68 852
853 funny user@domain WRONG
854 "funny user"@domain RIGHT, recommended
855 <"funny user"@domain> OK
856
406c51ee 857=head1 SEE ALSO
858
859L<Net::Cmd>
860
861=head1 AUTHOR
862
863Graham Barr <gbarr@pobox.com>
864
865=head1 COPYRIGHT
866
f92f3fcb 867Copyright (c) 1995-2004 Graham Barr. All rights reserved.
406c51ee 868This program is free software; you can redistribute it and/or modify
869it under the same terms as Perl itself.
870
871=cut