1Sendmail(3)           User Contributed Perl Documentation          Sendmail(3)
2
3
4

NAME

6       Mail::Sendmail v. 0.79 - Simple platform independent mailer
7

SYNOPSIS

9         use Mail::Sendmail;
10
11         %mail = ( To      => 'you@there.com',
12                   From    => 'me@here.com',
13                   Message => "This is a very short message"
14                  );
15
16         sendmail(%mail) or die $Mail::Sendmail::error;
17
18         print "OK. Log says:\n", $Mail::Sendmail::log;
19

DESCRIPTION

21       Simple platform independent e-mail from your perl script. Only requires
22       Perl 5 and a network connection.
23
24       Mail::Sendmail contains mainly &sendmail, which takes a hash with the
25       message to send and sends it. It is intended to be very easy to setup
26       and use. See also "FEATURES" below.
27

INSTALLATION

29       Best
30           "perl -MCPAN -e "install Mail::Sendmail""
31
32       Traditional
33               perl Makefile.PL
34               make
35               make test
36               make install
37
38       Manual
39           Copy Sendmail.pm to Mail/ in your Perl lib directory.
40
41               (eg. c:\Perl\site\lib\Mail\
42                or  /usr/lib/perl5/site_perl/Mail/
43                or whatever it is on your system.
44                They are listed when you type C< perl -V >)
45
46       ActivePerl's PPM
47           ppm install --location=http://alma.ch/perl/ppm Mail-Sendmail
48
49           But this way you don't get a chance to have a look at other files
50           (Changes, Todo, test.pl, ...).
51
52       At the top of Sendmail.pm, set your default SMTP server(s), unless you
53       specify it with each message, or want to use the default (localhost).
54
55       Install MIME::QuotedPrint. This is not required but strongly
56       recommended.
57

FEATURES

59       Automatic time zone detection, Date: header, MIME quoted-printable
60       encoding (if MIME::QuotedPrint installed), all of which can be
61       overridden.
62
63       Bcc: and Cc: support.
64
65       Allows real names in From:, To: and Cc: fields
66
67       Doesn't send an X-Mailer: header (unless you do), and allows you to
68       send any header(s) you want.
69
70       Configurable retries and use of alternate servers if your mail server
71       is down
72
73       Good plain text error reporting
74

LIMITATIONS

76       Headers are not encoded, even if they have accented characters.
77
78       No suport for the SMTP AUTH extension.
79
80       Since the whole message is in memory, it's not suitable for sending
81       very big attached files.
82
83       The SMTP server has to be set manually in Sendmail.pm or in your
84       script, unless you have a mail server on localhost.
85
86       Doesn't work on OpenVMS, I was told. Cannot test this myself.
87

CONFIGURATION

89       Default SMTP server(s)
90           This is probably all you want to configure. It is usually done
91           through $mailcfg{smtp}, which you can edit at the top of the
92           Sendmail.pm file.  This is a reference to a list of SMTP servers.
93           You can also set it from your script:
94
95           "unshift @{$Mail::Sendmail::mailcfg{'smtp'}} , 'my.mail.server';"
96
97           Alternatively, you can specify the server in the %mail hash you
98           send from your script, which will do the same thing:
99
100           "$mail{smtp} = 'my.mail.server';"
101
102           A future version will (hopefully) try to set useful defaults for
103           you during the Makefile.PL.
104
105       Other configuration settings
106           See %mailcfg under "DETAILS" below for other configuration options.
107

DETAILS

109   sendmail()
110       sendmail is the only thing exported to your namespace by default
111
112       "sendmail(%mail) || print "Error sending mail:
113       $Mail::Sendmail::error\n";"
114
115       It takes a hash containing the full message, with keys for all headers,
116       body, and optionally for another non-default SMTP server and/or port.
117
118       It returns 1 on success or 0 on error, and rewrites
119       $Mail::Sendmail::error and $Mail::Sendmail::log.
120
121       Keys are NOT case-sensitive.
122
123       The colon after headers is not necessary.
124
125       The Body part key can be called 'Body', 'Message' or 'Text'.
126
127       The SMTP server key can be called 'Smtp' or 'Server'. If the connection
128       to this one fails, the other ones in $mailcfg{smtp} will still be
129       tried.
130
131       The following headers are added unless you specify them yourself:
132
133           Mime-Version: 1.0
134           Content-Type: 'text/plain; charset="iso-8859-1"'
135
136           Content-Transfer-Encoding: quoted-printable
137           or (if MIME::QuotedPrint not installed)
138           Content-Transfer-Encoding: 8bit
139
140           Date: [string returned by time_to_date()]
141
142       If you wish to use an envelope sender address different than the From:
143       address, set $mail{Sender} in your %mail hash.
144
145       The following are not exported by default, but you can still access
146       them with their full name, or request their export on the use line like
147       in: "use Mail::Sendmail qw(sendmail $address_rx time_to_date);"
148
149   Mail::Sendmail::time_to_date()
150       convert time ( as from "time()" ) to an RFC 822 compliant string for
151       the Date header. See also "%Mail::Sendmail::mailcfg".
152
153   $Mail::Sendmail::error
154       When you don't run with the -w flag, the module sends no errors to
155       STDERR, but puts anything it has to complain about in here. You should
156       probably always check if it says something.
157
158   $Mail::Sendmail::log
159       A summary that you could write to a log file after each send
160
161   $Mail::Sendmail::address_rx
162       A handy regex to recognize e-mail addresses.
163
164       A correct regex for valid e-mail addresses was written by one of the
165       judges in the obfuscated Perl contest... :-) It is quite big. This one
166       is an attempt to a reasonable compromise, and should accept all real-
167       world internet style addresses. The domain part is required and
168       comments or characters that would need to be quoted are not supported.
169
170         Example:
171           $rx = $Mail::Sendmail::address_rx;
172           if (/$rx/) {
173             $address=$1;
174             $user=$2;
175             $domain=$3;
176           }
177
178   %Mail::Sendmail::mailcfg
179       This hash contains all configuration options. You normally edit it once
180       (if ever) in Sendmail.pm and forget about it, but you could also access
181       it from your scripts. For readability, I'll assume you have imported it
182       (with something like "use Mail::Sendmail qw(sendmail %mailcfg)").
183
184       The keys are not case-sensitive: they are all converted to lowercase
185       before use. Writing "$mailcfg{Port} = 2525;" is OK: the default
186       $mailcfg{port} (25) will be deleted and replaced with your new value of
187       2525.
188
189       $mailcfg{smtp}
190           "$mailcfg{smtp} = [qw(localhost my.other.mail.server)];"
191
192           This is a reference to a list of smtp servers, so if your main
193           server is down, the module tries the next one. If one of your
194           servers uses a special port, add it to the server name with a colon
195           in front, to override the default port (like in
196           my.special.server:2525).
197
198           Default: localhost.
199
200       $mailcfg{from}
201           "$mailcfg{from} = 'Mailing script me@mydomain.com';"
202
203           From address used if you don't supply one in your script. Should
204           not be of type 'user@localhost' since that may not be valid on the
205           recipient's host.
206
207           Default: undefined.
208
209       $mailcfg{mime}
210           "$mailcfg{mime} = 1;"
211
212           Set this to 0 if you don't want any automatic MIME encoding. You
213           normally don't need this, the module should 'Do the right thing'
214           anyway.
215
216           Default: 1;
217
218       $mailcfg{retries}
219           "$mailcfg{retries} = 1;"
220
221           How many times should the connection to the same SMTP server be
222           retried in case of a failure.
223
224           Default: 1;
225
226       $mailcfg{delay}
227           "$mailcfg{delay} = 1;"
228
229           Number of seconds to wait between retries. This delay also happens
230           before trying the next server in the list, if the retries for the
231           current server have been exhausted. For CGI scripts, you want few
232           retries and short delays to return with a results page before the
233           http connection times out. For unattended scripts, you may want to
234           use many retries and long delays to have a good chance of your mail
235           being sent even with temporary failures on your network.
236
237           Default: 1 (second);
238
239       $mailcfg{tz}
240           "$mailcfg{tz} = '+0800';"
241
242           Normally, your time zone is set automatically, from the difference
243           between "time()" and "gmtime()". This allows you to override
244           automatic detection in cases where your system is confused (such as
245           some Win32 systems in zones which do not use daylight savings time:
246           see Microsoft KB article Q148681)
247
248           Default: undefined (automatic detection at run-time).
249
250       $mailcfg{port}
251           "$mailcfg{port} = 25;"
252
253           Port used when none is specified in the server name.
254
255           Default: 25.
256
257       $mailcfg{debug}
258           "$mailcfg{debug} = 0;"
259
260           Prints stuff to STDERR. Current maximum is 6, which prints the
261           whole SMTP session, except data exceeding 500 bytes.
262
263           Default: 0;
264
265   $Mail::Sendmail::VERSION
266       The package version number (you can not import this one)
267
268   Configuration variables from previous versions
269       The following global variables were used in version 0.74 for
270       configuration.  As from version 0.78_1, they are not supported anymore.
271       Use the %mailcfg hash if you need to access the configuration from your
272       scripts.
273
274       $Mail::Sendmail::default_smtp_server
275       $Mail::Sendmail::default_smtp_port
276       $Mail::Sendmail::default_sender
277       $Mail::Sendmail::TZ
278       $Mail::Sendmail::connect_retries
279       $Mail::Sendmail::retry_delay
280       $Mail::Sendmail::use_MIME
281

ANOTHER EXAMPLE

283         use Mail::Sendmail;
284
285         print "Testing Mail::Sendmail version $Mail::Sendmail::VERSION\n";
286         print "Default server: $Mail::Sendmail::mailcfg{smtp}->[0]\n";
287         print "Default sender: $Mail::Sendmail::mailcfg{from}\n";
288
289         %mail = (
290             #To      => 'No to field this time, only Bcc and Cc',
291             #From    => 'not needed, use default',
292             Bcc     => 'Someone <him@there.com>, Someone else her@there.com',
293             # only addresses are extracted from Bcc, real names disregarded
294             Cc      => 'Yet someone else <xz@whatever.com>',
295             # Cc will appear in the header. (Bcc will not)
296             Subject => 'Test message',
297             'X-Mailer' => "Mail::Sendmail version $Mail::Sendmail::VERSION",
298         );
299
300
301         $mail{Smtp} = 'special_server.for-this-message-only.domain.com';
302         $mail{'X-custom'} = 'My custom additionnal header';
303         $mail{'mESSaGE : '} = "The message key looks terrible, but works.";
304         # cheat on the date:
305         $mail{Date} = Mail::Sendmail::time_to_date( time() - 86400 );
306
307         if (sendmail %mail) { print "Mail sent OK.\n" }
308         else { print "Error sending mail: $Mail::Sendmail::error \n" }
309
310         print "\n\$Mail::Sendmail::log says:\n", $Mail::Sendmail::log;
311
312       Also see http://alma.ch/perl/Mail-Sendmail-FAQ.html for examples of
313       HTML mail and sending attachments.
314

CHANGES

316       Main changes since version 0.78:
317
318       Added "/" (\x2F) as a valid character in mailbox part.
319
320       Removed old configuration variables which are not used anymore since
321       version 0.74.
322
323       Added support for different envelope sender (through $mail{Sender})
324
325       Changed case of headers: first character after "-" also uppercased
326
327       Support for multi-line server responses
328
329       Localized $\ and $_
330
331       Some internal rewrites and documentation updates
332
333       Fixed old bug of dot as 76th character on line disappearing.
334
335       Fixed very old bug where port number was not extracted from stuff like
336       'my.server:2525'.
337
338       Fixed time_to_date bug with negative half-hour zones (only
339       Newfoundland?)
340
341       Added seconds to date string
342
343       Now uses Sys::Hostname to get the hostname for HELO. (This may break
344       the module on some very old Win32 Perls where Sys::Hostname was broken)
345
346       Enable full session output for debugging
347
348       See the Changes file for the full history. If you don't have it because
349       you installed through PPM, you can also find the latest one on
350       http://alma.ch/perl/scripts/Sendmail/Changes.
351

AUTHOR

353       Milivoj Ivkovic <mi\x40alma.ch> ("\x40" is "@" of course)
354

NOTES

356       MIME::QuotedPrint is used by default on every message if available. It
357       allows reliable sending of accented characters, and also takes care of
358       too long lines (which can happen in HTML mails). It is available in the
359       MIME-Base64 package at http://www.perl.com/CPAN/modules/by-module/MIME/
360       or through PPM.
361
362       Look at http://alma.ch/perl/Mail-Sendmail-FAQ.html for additional info
363       (CGI, examples of sending attachments, HTML mail etc...)
364
365       You can use this module freely. (Someone complained this is too vague.
366       So, more precisely: do whatever you want with it, but be warned that
367       terrible things will happen to you if you use it badly, like for
368       sending spam, or ...?)
369
370       Thanks to the many users who sent me feedback, bug reports,
371       suggestions, etc.  And please excuse me if I forgot to answer your
372       mail. I am not always reliabe in answering mail. I intend to set up a
373       mailing list soon.
374
375       Last revision: 06.02.2003. Latest version should be available on CPAN:
376       http://www.cpan.org/modules/by-authors/id/M/MI/MIVKOVIC/.
377
378
379
380perl v5.12.0                      2003-02-06                       Sendmail(3)
Impressum