summaryrefslogtreecommitdiff
path: root/cpan/libnet/demos/smtp.self
blob: 5cfbc2b824611127dadf47aa69ad16e1c5f491a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/local/bin/perl -w

use blib;
use Net::SMTP;
use Getopt::Long;

=head1 NAME

    smtp.self - mail a message via smtp

=head1 DESCRIPTION

C<smtp.self> will attempt to send a message to a given user

=head1 OPTIONS

=over 4

=item -debug

Enabe the output of dubug information

=item -help

Display this help text and quit

=item -user USERNAME

Send the message to C<USERNAME>

=head1 EXAMPLE

    demos/smtp.self  -user foo.bar

    demos/smtp.self -debug -user Graham.Barr

=back

=cut

$opt_debug = undef;
$opt_user = undef;
$opt_help = undef;
GetOptions(qw(debug user=s help));

exec("pod2text $0")
    if defined $opt_help;

Net::SMTP->debug(1) if $opt_debug;

$smtp = Net::SMTP->new("mailhost");

$user = $opt_user || $ENV{USER} || $ENV{LOGNAME};

$smtp->mail($user) && $smtp->to($user);
$smtp->reset;

if($smtp->mail($user) && $smtp->to($user))
 {
  $smtp->data();

  map { s/-USER-/$user/g } @data=<DATA>;

  $smtp->datasend(@data);
  $smtp->dataend;
 }
else
 {
  warn $smtp->message;
 }

$smtp->quit;

__DATA__
To: <-USER->
Subject: A test message

The message was sent directly via SMTP using Net::SMTP
.
The message was sent directly via SMTP using Net::SMTP