perl-libnet.git  about / heads / tags
Unnamed repository; edit this file 'description' to name the repository.
blob e34d585d425f083bcdf6bdd90b1f4adb94dc94bf 1293 bytes (raw)
$ git show nntp-compress:demos/smtp.self	# shows this blob on the CLI

 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
81
82
83
84
85
 
#!perl

use 5.008001;

use strict;
use warnings;

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

=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>

=back

=head1 EXAMPLE

    demos/smtp.self  -user foo.bar

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

=cut

our $opt_debug = undef;
our $opt_user = undef;
our $opt_help = undef;
GetOptions(qw(debug user=s help));
exec("pod2text $0")
    if defined $opt_help;

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

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

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

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

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

  my @data;
  map { s/-USER-/$user/g } @data=<DATA>; ## no critic (ControlStructures::ProhibitMutatingListFunctions)

  $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

git clone https://80x24.org/perl-libnet.git