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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| #!/usr/bin/perl -w
use Net::SMTP;
if(!$ARGV[0])
{
print 'File missing !'."\n";
exit;
}
open (FIC, $ARGV[0]) || die('read error');
my $i = 0;
my $data = '';
my $smtpserver = '';
my $port = '';
my $login = '';
my $pass = '';
my $to = '';
my $from = '';
my $reply = '';
my $subject = '';
while(<FIC>)
{
$i = $i >= 0 ? 0 : -1;
if(substr($_, 0, 9) eq 'SMTP_ADDR')
{
$smtpserver = substr($_, 10);
chomp($smtpserver);
$i=1;
}
if(substr($_, 0, 9) eq 'SMTP_PORT')
{
$port = substr($_, 10);
chomp($port);
$i=1;
}
if(substr($_, 0, 10) eq 'SMTP_LOGIN')
{
$login = substr($_, 11);
chomp($login);
$i=1;
}
if(substr($_, 0, 13) eq 'SMTP_PASSWORD')
{
$pass = substr($_, 14);
chomp($pass);
$i=1;
}
if(substr($_, 0, 7) eq 'MAIL_TO')
{
$to = substr($_, 8);
chomp($to);
$i=1;
}
if(substr($_, 0, 10) eq 'MAIL_REPLY')
{
$reply = substr($_, 11);
chomp($reply);
$i=1;
}
if(substr($_, 0, 9) eq 'MAIL_FROM')
{
$from = substr($_, 10);
chomp($from);
$i=1;
}
if(substr($_, 0, 12) eq 'MAIL_SUBJECT')
{
$subject = substr($_, 13);
chomp($subject);
$i=1;
}
if(!$i || $i == -1)
{
$data .= $_;
$i = -1;
}
}
$data .= "\n";
$smtpserver .= ':'.$port if $port;
$smtp = Net::SMTP->new($smtpserver."\n", Timeout => 10) || die ('echec de connexion'."\n");
$smtp->auth($login, $pass) if $login;
$smtp->mail($from."\n");
$smtp->to($to."\n");
$smtp->data();
#$smtp->datasend('To: '.$to."\n");
#$smtp->datasend('From: '.$from."\n");
#$smtp->datasend('Reply-to: '.$reply."\n") if $reply;
$smtp->datasend('X-Mailer: xxxxxxxx."\n");
$smtp->datasend('Subject: '.$subject."\n");
$smtp->datasend( "Content-type: text/html\n");
$smtp->datasend("\n");
$smtp->datasend($data."\n");
$smtp->dataend();
$smtp->quit();
close(FIC);
exit; |
Partager