Debian Codegraph @

upstream/debian-unstable/man3/Net::SMTP.3perl

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45)
3 .\"
4 .\" Standard preamble:
5 .\" ========================================================================
6 .de Sp \" Vertical space (when we can't use .PP)
7 .if t .sp .5v
8 .if n .sp
9 ..
10 .de Vb \" Begin verbatim text
11 .ft CW
12 .nf
13 .ne \\$1
14 ..
15 .de Ve \" End verbatim text
16 .ft R
17 .fi
18 ..
19 .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
20 .ie n \{\
21 . ds C` ""
22 . ds C' ""
23 'br\}
24 .el\{\
25 . ds C`
26 . ds C'
27 'br\}
28 .\"
29 .\" Escape single quotes in literal strings from groff's Unicode transform.
30 .ie \n(.g .ds Aq \(aq
31 .el .ds Aq '
32 .\"
33 .\" If the F register is >0, we'll generate index entries on stderr for
34 .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
35 .\" entries marked with X<> in POD. Of course, you'll have to process the
36 .\" output yourself in some meaningful fashion.
37 .\"
38 .\" Avoid warning from groff about undefined register 'F'.
39 .de IX
40 ..
41 .nr rF 0
42 .if \n(.g .if rF .nr rF 1
43 .if (\n(rF:(\n(.g==0)) \{\
44 . if \nF \{\
45 . de IX
46 . tm Index:\\$1\t\\n%\t"\\$2"
47 ..
48 . if !\nF==2 \{\
49 . nr % 0
50 . nr F 2
51 . \}
52 . \}
53 .\}
54 .rr rF
55 .\" ========================================================================
56 .\"
57 .IX Title "Net::SMTP 3perl"
58 .TH Net::SMTP 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide"
59 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
60 .\" way too many mistakes in technical documents.
61 .if n .ad l
62 .nh
63 .SH NAME
64 Net::SMTP \- Simple Mail Transfer Protocol Client
65 .SH SYNOPSIS
66 .IX Header "SYNOPSIS"
67 .Vb 1
68 \& use Net::SMTP;
69 \&
70 \& # Constructors
71 \& $smtp = Net::SMTP\->new(\*(Aqmailhost\*(Aq);
72 \& $smtp = Net::SMTP\->new(\*(Aqmailhost\*(Aq, Timeout => 60);
73 .Ve
74 .SH DESCRIPTION
75 .IX Header "DESCRIPTION"
76 This module implements a client interface to the SMTP and ESMTP
77 protocol, enabling a perl5 application to talk to SMTP servers. This
78 documentation assumes that you are familiar with the concepts of the
79 SMTP protocol described in RFC2821.
80 With IO::Socket::SSL installed it also provides support for implicit and
81 explicit TLS encryption, i.e. SMTPS or SMTP+STARTTLS.
82 .PP
83 The Net::SMTP class is a subclass of Net::Cmd and (depending on avaibility) of
84 IO::Socket::IP, IO::Socket::INET6 or IO::Socket::INET.
85 .SS "Class Methods"
86 .IX Subsection "Class Methods"
87 .ie n .IP """new([$host][, %options])""" 4
88 .el .IP "\f(CWnew([$host][, %options])\fR" 4
89 .IX Item "new([$host][, %options])"
90 This is the constructor for a new Net::SMTP object. \f(CW$host\fR is the
91 name of the remote host to which an SMTP connection is required.
92 .Sp
93 On failure \f(CW\*(C`undef\*(C'\fR will be returned and \f(CW$@\fR will contain the reason
94 for the failure.
95 .Sp
96 \&\f(CW$host\fR is optional. If \f(CW$host\fR is not given then it may instead be
97 passed as the \f(CW\*(C`Host\*(C'\fR option described below. If neither is given then
98 the \f(CW\*(C`SMTP_Hosts\*(C'\fR specified in \f(CW\*(C`Net::Config\*(C'\fR will be used.
99 .Sp
100 \&\f(CW%options\fR are passed in a hash like fashion, using key and value pairs.
101 Possible options are:
102 .Sp
103 \&\fBHello\fR \- SMTP requires that you identify yourself. This option
104 specifies a string to pass as your mail domain. If not given localhost.localdomain
105 will be used.
106 .Sp
107 \&\fBSendHello\fR \- If false then the EHLO (or HELO) command that is normally sent
108 when constructing the object will not be sent. In that case the command will
109 have to be sent manually by calling \f(CWhello()\fR instead.
110 .Sp
111 \&\fBHost\fR \- SMTP host to connect to. It may be a single scalar (hostname[:port]),
112 as defined for the \f(CW\*(C`PeerAddr\*(C'\fR option in IO::Socket::INET, or a reference to
113 an array with hosts to try in turn. The "host" method will return the value
114 which was used to connect to the host.
115 Format \- \f(CW\*(C`PeerHost\*(C'\fR from IO::Socket::INET new method.
116 .Sp
117 \&\fBPort\fR \- port to connect to.
118 Default \- 25 for plain SMTP and 465 for immediate SSL.
119 .Sp
120 \&\fBSSL\fR \- If the connection should be done from start with SSL, contrary to later
121 upgrade with \f(CW\*(C`starttls\*(C'\fR.
122 You can use SSL arguments as documented in IO::Socket::SSL, but it will
123 usually use the right arguments already.
124 .Sp
125 \&\fBLocalAddr\fR and \fBLocalPort\fR \- These parameters are passed directly
126 to IO::Socket to allow binding the socket to a specific local address and port.
127 .Sp
128 \&\fBDomain\fR \- This parameter is passed directly to IO::Socket and makes it
129 possible to enforce IPv4 connections even if IO::Socket::IP is used as super
130 class. Alternatively \fBFamily\fR can be used.
131 .Sp
132 \&\fBTimeout\fR \- Maximum time, in seconds, to wait for a response from the
133 SMTP server (default: 120)
134 .Sp
135 \&\fBExactAddresses\fR \- If true then all \f(CW$address\fR arguments must be as
136 defined by \f(CW\*(C`addr\-spec\*(C'\fR in RFC2822. If not given, or false, then
137 Net::SMTP will attempt to extract the address from the value passed.
138 .Sp
139 \&\fBDebug\fR \- Enable debugging information
140 .Sp
141 Example:
142 .Sp
143 .Vb 5
144 \& $smtp = Net::SMTP\->new(\*(Aqmailhost\*(Aq,
145 \& Hello => \*(Aqmy.mail.domain\*(Aq,
146 \& Timeout => 30,
147 \& Debug => 1,
148 \& );
149 \&
150 \& # the same
151 \& $smtp = Net::SMTP\->new(
152 \& Host => \*(Aqmailhost\*(Aq,
153 \& Hello => \*(Aqmy.mail.domain\*(Aq,
154 \& Timeout => 30,
155 \& Debug => 1,
156 \& );
157 \&
158 \& # the same with direct SSL
159 \& $smtp = Net::SMTP\->new(\*(Aqmailhost\*(Aq,
160 \& Hello => \*(Aqmy.mail.domain\*(Aq,
161 \& Timeout => 30,
162 \& Debug => 1,
163 \& SSL => 1,
164 \& );
165 \&
166 \& # Connect to the default server from Net::config
167 \& $smtp = Net::SMTP\->new(
168 \& Hello => \*(Aqmy.mail.domain\*(Aq,
169 \& Timeout => 30,
170 \& );
171 .Ve
172 .SH "Object Methods"
173 .IX Header "Object Methods"
174 Unless otherwise stated all methods return either a \fItrue\fR or \fIfalse\fR
175 value, with \fItrue\fR meaning that the operation was a success. When a method
176 states that it returns a value, failure will be returned as \fIundef\fR or an
177 empty list.
178 .PP
179 \&\f(CW\*(C`Net::SMTP\*(C'\fR inherits from \f(CW\*(C`Net::Cmd\*(C'\fR so methods defined in \f(CW\*(C`Net::Cmd\*(C'\fR may
180 be used to send commands to the remote SMTP server in addition to the methods
181 documented here.
182 .ie n .IP banner() 4
183 .el .IP \f(CWbanner()\fR 4
184 .IX Item "banner()"
185 Returns the banner message which the server replied with when the
186 initial connection was made.
187 .ie n .IP domain() 4
188 .el .IP \f(CWdomain()\fR 4
189 .IX Item "domain()"
190 Returns the domain that the remote SMTP server identified itself as during
191 connection.
192 .ie n .IP hello($domain) 4
193 .el .IP \f(CWhello($domain)\fR 4
194 .IX Item "hello($domain)"
195 Tell the remote server the mail domain which you are in using the EHLO
196 command (or HELO if EHLO fails). Since this method is invoked
197 automatically when the Net::SMTP object is constructed the user should
198 normally not have to call it manually.
199 .ie n .IP host() 4
200 .el .IP \f(CWhost()\fR 4
201 .IX Item "host()"
202 Returns the value used by the constructor, and passed to IO::Socket::INET,
203 to connect to the host.
204 .ie n .IP etrn($domain) 4
205 .el .IP \f(CWetrn($domain)\fR 4
206 .IX Item "etrn($domain)"
207 Request a queue run for the \f(CW$domain\fR given.
208 .ie n .IP starttls(%sslargs) 4
209 .el .IP \f(CWstarttls(%sslargs)\fR 4
210 .IX Item "starttls(%sslargs)"
211 Upgrade existing plain connection to SSL.
212 You can use SSL arguments as documented in IO::Socket::SSL, but it will
213 usually use the right arguments already.
214 .ie n .IP """auth($username, $password)""" 4
215 .el .IP "\f(CWauth($username, $password)\fR" 4
216 .IX Item "auth($username, $password)"
217 .PD 0
218 .ie n .IP auth($sasl) 4
219 .el .IP \f(CWauth($sasl)\fR 4
220 .IX Item "auth($sasl)"
221 .PD
222 Attempt SASL authentication. Requires Authen::SASL module. The first form
223 constructs a new Authen::SASL object using the given username and password;
224 the second form uses the given Authen::SASL object.
225 .ie n .IP """mail($address[, %options])""" 4
226 .el .IP "\f(CWmail($address[, %options])\fR" 4
227 .IX Item "mail($address[, %options])"
228 .PD 0
229 .ie n .IP send($address) 4
230 .el .IP \f(CWsend($address)\fR 4
231 .IX Item "send($address)"
232 .ie n .IP send_or_mail($address) 4
233 .el .IP \f(CWsend_or_mail($address)\fR 4
234 .IX Item "send_or_mail($address)"
235 .ie n .IP send_and_mail($address) 4
236 .el .IP \f(CWsend_and_mail($address)\fR 4
237 .IX Item "send_and_mail($address)"
238 .PD
239 Send the appropriate command to the server MAIL, SEND, SOML or SAML. \f(CW$address\fR
240 is the address of the sender. This initiates the sending of a message. The
241 method \f(CW\*(C`recipient\*(C'\fR should be called for each address that the message is to
242 be sent to.
243 .Sp
244 The \f(CW\*(C`mail\*(C'\fR method can take some additional ESMTP \f(CW%options\fR which is passed
245 in hash like fashion, using key and value pairs. Possible options are:
246 .Sp
247 .Vb 8
248 \& Size => <bytes>
249 \& Return => "FULL" | "HDRS"
250 \& Bits => "7" | "8" | "binary"
251 \& Transaction => <ADDRESS>
252 \& Envelope => <ENVID> # xtext\-encodes its argument
253 \& ENVID => <ENVID> # similar to Envelope, but expects argument encoded
254 \& XVERP => 1
255 \& AUTH => <submitter> # encoded address according to RFC 2554
256 .Ve
257 .Sp
258 The \f(CW\*(C`Return\*(C'\fR and \f(CW\*(C`Envelope\*(C'\fR parameters are used for DSN (Delivery
259 Status Notification).
260 .Sp
261 The submitter address in \f(CW\*(C`AUTH\*(C'\fR option is expected to be in a format as
262 required by RFC 2554, in an RFC2821\-quoted form and xtext-encoded, or <> .
263 .ie n .IP reset() 4
264 .el .IP \f(CWreset()\fR 4
265 .IX Item "reset()"
266 Reset the status of the server. This may be called after a message has been
267 initiated, but before any data has been sent, to cancel the sending of the
268 message.
269 .ie n .IP """recipient($address[, $address[, ...]][, %options])""" 4
270 .el .IP "\f(CWrecipient($address[, $address[, ...]][, %options])\fR" 4
271 .IX Item "recipient($address[, $address[, ...]][, %options])"
272 Notify the server that the current message should be sent to all of the
273 addresses given. Each address is sent as a separate command to the server.
274 Should the sending of any address result in a failure then the process is
275 aborted and a \fIfalse\fR value is returned. It is up to the user to call
276 \&\f(CW\*(C`reset\*(C'\fR if they so desire.
277 .Sp
278 The \f(CW\*(C`recipient\*(C'\fR method can also pass additional case-sensitive \f(CW%options\fR as an
279 anonymous hash using key and value pairs. Possible options are:
280 .Sp
281 .Vb 3
282 \& Notify => [\*(AqNEVER\*(Aq] or [\*(AqSUCCESS\*(Aq,\*(AqFAILURE\*(Aq,\*(AqDELAY\*(Aq] (see below)
283 \& ORcpt => <ORCPT>
284 \& SkipBad => 1 (to ignore bad addresses)
285 .Ve
286 .Sp
287 If \f(CW\*(C`SkipBad\*(C'\fR is true the \f(CW\*(C`recipient\*(C'\fR will not return an error when a bad
288 address is encountered and it will return an array of addresses that did
289 succeed.
290 .Sp
291 .Vb 5
292 \& $smtp\->recipient($recipient1,$recipient2); # Good
293 \& $smtp\->recipient($recipient1,$recipient2, { SkipBad => 1 }); # Good
294 \& $smtp\->recipient($recipient1,$recipient2, { Notify => [\*(AqFAILURE\*(Aq,\*(AqDELAY\*(Aq], SkipBad => 1 }); # Good
295 \& @goodrecips=$smtp\->recipient(@recipients, { Notify => [\*(AqFAILURE\*(Aq], SkipBad => 1 }); # Good
296 \& $smtp\->recipient("$recipient,$recipient2"); # BAD
297 .Ve
298 .Sp
299 Notify is used to request Delivery Status Notifications (DSNs), but your
300 SMTP/ESMTP service may not respect this request depending upon its version and
301 your site's SMTP configuration.
302 .Sp
303 Leaving out the Notify option usually defaults an SMTP service to its default
304 behavior equivalent to ['FAILURE'] notifications only, but again this may be
305 dependent upon your site's SMTP configuration.
306 .Sp
307 The NEVER keyword must appear by itself if used within the Notify option and "requests
308 that a DSN not be returned to the sender under any conditions."
309 .Sp
310 .Vb 1
311 \& {Notify => [\*(AqNEVER\*(Aq]}
312 \&
313 \& $smtp\->recipient(@recipients, { Notify => [\*(AqNEVER\*(Aq], SkipBad => 1 }); # Good
314 .Ve
315 .Sp
316 You may use any combination of these three values 'SUCCESS','FAILURE','DELAY' in
317 the anonymous array reference as defined by RFC3461 (see
318 <https://www.ietf.org/rfc/rfc3461.txt> for more information. Note: quotations
319 in this topic from same.).
320 .Sp
321 A Notify parameter of 'SUCCESS' or 'FAILURE' "requests that a DSN be issued on
322 successful delivery or delivery failure, respectively."
323 .Sp
324 A Notify parameter of 'DELAY' "indicates the sender's willingness to receive
325 delayed DSNs. Delayed DSNs may be issued if delivery of a message has been
326 delayed for an unusual amount of time (as determined by the Message Transfer
327 Agent (MTA) at which the message is delayed), but the final delivery status
328 (whether successful or failure) cannot be determined. The absence of the DELAY
329 keyword in a NOTIFY parameter requests that a "delayed" DSN NOT be issued under
330 any conditions."
331 .Sp
332 .Vb 1
333 \& {Notify => [\*(AqSUCCESS\*(Aq,\*(AqFAILURE\*(Aq,\*(AqDELAY\*(Aq]}
334 \&
335 \& $smtp\->recipient(@recipients, { Notify => [\*(AqFAILURE\*(Aq,\*(AqDELAY\*(Aq], SkipBad => 1 }); # Good
336 .Ve
337 .Sp
338 ORcpt is also part of the SMTP DSN extension according to RFC3461.
339 It is used to pass along the original recipient that the mail was first
340 sent to. The machine that generates a DSN will use this address to inform
341 the sender, because he can't know if recipients get rewritten by mail servers.
342 It is expected to be in a format as required by RFC3461, xtext-encoded.
343 .ie n .IP """to($address[, $address[, ...]])""" 4
344 .el .IP "\f(CWto($address[, $address[, ...]])\fR" 4
345 .IX Item "to($address[, $address[, ...]])"
346 .PD 0
347 .ie n .IP """cc($address[, $address[, ...]])""" 4
348 .el .IP "\f(CWcc($address[, $address[, ...]])\fR" 4
349 .IX Item "cc($address[, $address[, ...]])"
350 .ie n .IP """bcc($address[, $address[, ...]])""" 4
351 .el .IP "\f(CWbcc($address[, $address[, ...]])\fR" 4
352 .IX Item "bcc($address[, $address[, ...]])"
353 .PD
354 Synonyms for \f(CW\*(C`recipient\*(C'\fR.
355 .ie n .IP data([$data]) 4
356 .el .IP \f(CWdata([$data])\fR 4
357 .IX Item "data([$data])"
358 Initiate the sending of the data from the current message.
359 .Sp
360 \&\f(CW$data\fR may be a reference to a list or a list and must be encoded by the
361 caller to octets of whatever encoding is required, e.g. by using the Encode
362 module's \f(CWencode()\fR function.
363 .Sp
364 If specified the contents of \f(CW$data\fR and a termination string \f(CW".\er\en"\fR is
365 sent to the server. The result will be true if the data was accepted.
366 .Sp
367 If \f(CW$data\fR is not specified then the result will indicate that the server
368 wishes the data to be sent. The data must then be sent using the \f(CW\*(C`datasend\*(C'\fR
369 and \f(CW\*(C`dataend\*(C'\fR methods described in Net::Cmd.
370 .ie n .IP bdat($data) 4
371 .el .IP \f(CWbdat($data)\fR 4
372 .IX Item "bdat($data)"
373 .PD 0
374 .ie n .IP bdatlast($data) 4
375 .el .IP \f(CWbdatlast($data)\fR 4
376 .IX Item "bdatlast($data)"
377 .PD
378 Use the alternate \f(CW$data\fR command "BDAT" of the data chunking service extension
379 defined in RFC1830 for efficiently sending large MIME messages.
380 .ie n .IP expand($address) 4
381 .el .IP \f(CWexpand($address)\fR 4
382 .IX Item "expand($address)"
383 Request the server to expand the given address Returns an array
384 which contains the text read from the server.
385 .ie n .IP verify($address) 4
386 .el .IP \f(CWverify($address)\fR 4
387 .IX Item "verify($address)"
388 Verify that \f(CW$address\fR is a legitimate mailing address.
389 .Sp
390 Most sites usually disable this feature in their SMTP service configuration.
391 Use "Debug => 1" option under \fBnew()\fR to see if disabled.
392 .ie n .IP help([$subject]) 4
393 .el .IP \f(CWhelp([$subject])\fR 4
394 .IX Item "help([$subject])"
395 Request help text from the server. Returns the text or undef upon failure
396 .ie n .IP quit() 4
397 .el .IP \f(CWquit()\fR 4
398 .IX Item "quit()"
399 Send the QUIT command to the remote SMTP server and close the socket connection.
400 .ie n .IP can_inet6() 4
401 .el .IP \f(CWcan_inet6()\fR 4
402 .IX Item "can_inet6()"
403 Returns whether we can use IPv6.
404 .ie n .IP can_ssl() 4
405 .el .IP \f(CWcan_ssl()\fR 4
406 .IX Item "can_ssl()"
407 Returns whether we can use SSL.
408 .SS Addresses
409 .IX Subsection "Addresses"
410 Net::SMTP attempts to DWIM with addresses that are passed. For
411 example an application might extract The From: line from an email
412 and pass that to \fBmail()\fR. While this may work, it is not recommended.
413 The application should really use a module like Mail::Address
414 to extract the mail address and pass that.
415 .PP
416 If \f(CW\*(C`ExactAddresses\*(C'\fR is passed to the constructor, then addresses
417 should be a valid rfc2821\-quoted address, although Net::SMTP will
418 accept the address surrounded by angle brackets.
419 .PP
420 .Vb 3
421 \& funny user@domain WRONG
422 \& "funny user"@domain RIGHT, recommended
423 \& <"funny user"@domain> OK
424 .Ve
425 .SH EXAMPLES
426 .IX Header "EXAMPLES"
427 This example prints the mail domain name of the SMTP server known as mailhost:
428 .PP
429 .Vb 1
430 \& #!/usr/local/bin/perl \-w
431 \&
432 \& use Net::SMTP;
433 \&
434 \& $smtp = Net::SMTP\->new(\*(Aqmailhost\*(Aq);
435 \& print $smtp\->domain,"\en";
436 \& $smtp\->quit;
437 .Ve
438 .PP
439 This example sends a small message to the postmaster at the SMTP server
440 known as mailhost:
441 .PP
442 .Vb 1
443 \& #!/usr/local/bin/perl \-w
444 \&
445 \& use Net::SMTP;
446 \&
447 \& my $smtp = Net::SMTP\->new(\*(Aqmailhost\*(Aq);
448 \&
449 \& $smtp\->mail($ENV{USER});
450 \& if ($smtp\->to(\*(Aqpostmaster\*(Aq)) {
451 \& $smtp\->data();
452 \& $smtp\->datasend("To: postmaster\en");
453 \& $smtp\->datasend("\en");
454 \& $smtp\->datasend("A simple test message\en");
455 \& $smtp\->dataend();
456 \& } else {
457 \& print "Error: ", $smtp\->message();
458 \& }
459 \&
460 \& $smtp\->quit;
461 .Ve
462 .SH EXPORTS
463 .IX Header "EXPORTS"
464 \&\fINone\fR.
465 .SH "KNOWN BUGS"
466 .IX Header "KNOWN BUGS"
467 See <https://rt.cpan.org/Dist/Display.html?Status=Active&Queue=libnet>.
468 .SH "SEE ALSO"
469 .IX Header "SEE ALSO"
470 Net::Cmd,
471 IO::Socket::SSL.
472 .SH AUTHOR
473 .IX Header "AUTHOR"
474 Graham Barr <[email protected] <mailto:[email protected]>>.
475 .PP
476 Steve Hay <[email protected] <mailto:[email protected]>> is now maintaining
477 libnet as of version 1.22_02.
478 .SH COPYRIGHT
479 .IX Header "COPYRIGHT"
480 Copyright (C) 1995\-2004 Graham Barr. All rights reserved.
481 .PP
482 Copyright (C) 2013\-2016, 2020 Steve Hay. All rights reserved.
483 .SH LICENCE
484 .IX Header "LICENCE"
485 This module is free software; you can redistribute it and/or modify it under the
486 same terms as Perl itself, i.e. under the terms of either the GNU General Public
487 License or the Artistic License, as specified in the \fILICENCE\fR file.
488 .SH VERSION
489 .IX Header "VERSION"
490 Version 3.15
491 .SH DATE
492 .IX Header "DATE"
493 20 March 2023
494 .SH HISTORY
495 .IX Header "HISTORY"
496 See the \fIChanges\fR file.