xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/lib/Net/demos/smtp.self (revision 0:68f95e015346)
1#!/usr/local/bin/perl -w
2
3use blib;
4use Net::SMTP;
5use Getopt::Long;
6
7=head1 NAME
8
9    smtp.self - mail a message via smtp
10
11=head1 DESCRIPTION
12
13C<smtp.self> will attempt to send a message to a given user
14
15=head1 OPTIONS
16
17=over 4
18
19=item -debug
20
21Enabe the output of dubug information
22
23=item -help
24
25Display this help text and quit
26
27=item -user USERNAME
28
29Send the message to C<USERNAME>
30
31=head1 EXAMPLE
32
33    demos/smtp.self  -user foo.bar
34
35    demos/smtp.self -debug -user Graham.Barr
36
37=back
38
39=cut
40
41$opt_debug = undef;
42$opt_user = undef;
43$opt_help = undef;
44GetOptions(qw(debug user=s help));
45
46exec("pod2text $0")
47    if defined $opt_help;
48
49Net::SMTP->debug(1) if $opt_debug;
50
51$smtp = Net::SMTP->new("mailhost");
52
53$user = $opt_user || $ENV{USER} || $ENV{LOGNAME};
54
55$smtp->mail($user) && $smtp->to($user);
56$smtp->reset;
57
58if($smtp->mail($user) && $smtp->to($user))
59 {
60  $smtp->data();
61
62  map { s/-USER-/$user/g } @data=<DATA>;
63
64  $smtp->datasend(@data);
65  $smtp->dataend;
66 }
67else
68 {
69  warn $smtp->message;
70 }
71
72$smtp->quit;
73
74__DATA__
75To: <-USER->
76Subject: A test message
77
78The message was sent directly via SMTP using Net::SMTP
79.
80The message was sent directly via SMTP using Net::SMTP
81