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