歡迎您光臨本站 註冊首頁

如何用smtp.pl進行smtp驗證收發郵件?

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

如何用smtp.pl進行smtp驗證收發郵件?

#!/usr/bin/perl -w

use Net::SMTP;
use Getopt::Long;
use MIME::Lite;

=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_help = undef;
GetOptions(qw(debug user=s help));

exec("pod2text $0")
   if defined $opt_help;
sub chk_args
{
if (@ARGV<4) {
       print "Usage: smtp Path FileName MailUsers Content FromUser\n";
       exit(0);
               }
       $path = $ARGV;
       $file_name = $ARGV;
       $title = $ARGV;
       $fromlocation = $ARGV;
       @files = `ls $path/$file_name`;
       $array_size = $#ARGV-2;
return(1);
}

sub send_mail($$$$)
{
my ($user,$file,$name,$ntitle)=@_;
##$smtp = MIME::Lite->new(From => 'STIT 137.200.32.51.',
$smtp = MIME::Lite->new(From => $fromlocation,
                       To => "$user",
                       Subject => "$ntitle",
###                     Subject => "$file, Please Check it...",
                       Type => 'multipart/mixed'
                       );
$smtp->attach(Type     => 'TEXT',
             Path     => "$file",
             Filename => "$name",
             Disposition => 'attachment'
            );
$smtp->attach(Type => 'TEXT',
               Data => "$ntitle");

$smtp->send('smtp',"mailhost")||die "You Don't Have Mail!";
}

&chk_args;
for ($i=2;$i<=$array_size;$i++) { ##從第三個參數開始
$mail_addr = $ARGV[$i];
$p = index($mail_addr,'@'); ##是否包含"@"
if ($p>=0) {  ##包含"@",是郵件地址
    foreach $send_file (@files) {
    chomp($send_file);
    @arr = split(/\//,$send_file);
    $send_name = $arr[$#arr];
    send_mail($mail_addr,$send_file,$send_name,$title);
    } #end foreach
}
else { ##不包含"@",是文件
    open(FL,"<$mail_addr");
    while(<FL>) { ##取文件中的郵件地址
      $mail=$_;
      foreach $send_file (@files) {
        chomp($send_file);
        @arr = split(/\//,$send_file);
        $send_name = $arr[$#arr];
        send_mail($mail,$send_file,$send_name,$title);
      } #end foreach
    } #end while
    close(FL);
    close(FL);
} #end if
} #end for

[火星人 ] 如何用smtp.pl進行smtp驗證收發郵件?已經有410次圍觀

http://coctec.com/docs/service/show-post-35599.html