
November 22nd, 2012, 02:02 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 2
Time spent in forums: 1 h 1 m 17 sec
Reputation Power: 0
|
|
|
Perl mail script using use IO::Socket;
Hello,
I use a perl script to send an email.
The mail has a subject and body.
Now we've to use a MS Exchange mail server and since then we do not receive any mail.
Before that we used a unix mail server and everything worked great.
I found out that if we use the MS mail server and send a mail with empty body the mail arrives at the user.
If I put just one letter in the body no mail will arrive.
I also made a tcpdump and noticed that the script fails somewhere because in the tcpdump I do no see a message ID.
I use the following perl script:
#!/usr/bin/perl
#
# Meelskript
#
#
# 25/10/04
#
# default configfile meelskript.cfg
use IO::Socket;
if (!$ARGV[0]) {
die "usage: ./meelskript.pl <configfile> <filetosend>\n";
}
if(!$ARGV[1]) {
die "usage: ./meelskript.pl <configfile> <filetosend>\n";
}
$configfile = $ARGV[0];
$file = $ARGV[1];
$date = `date +%d-%m-%Y`;
chomp($date);
if(!-e "$configfile") {
die "Can't access configfile: $configfile!\n";
}
# All OK, go for it!
open FILE, "<$configfile";
@config = <FILE>;
close FILE;
print "using configfile: $configfile\n";
foreach(@config) {
if($_ =~ /^mailserver/) {
$current = $_;
chomp($current);
($temp, $mailserver)=split(/\:\t*/,$current);
$mailserver =~ s/[\t|\s]//g;
if(!$mailserver) {
die "ENOMAILSERVER!\n";
}
}
elsif($_ =~/^mailport/) {
$current = $_;
chomp($current);
($temp, $mailport)=split(/\:\t*\D/,$current);
if(!$mailport) {
die "ENOMAILPORT!\n";
}
}
elsif($_ =~ /^mailaddresses/) {
$current = $_;
chomp($current);
($temp, $mailaddresses)=split(/\:\t*/,$current);
if(!$mailaddresses) {
die "ENOMAILADDRESSES!\n";
}
}
elsif($_ =~ /^subject/) {
$current = $_;
chomp($current);
($temp, $subject)=split(/\:\t*/,$current);
}
}
if(!-e $file) {
die "file $file not found!\n";
}
open FILE, "<$file";
@file = <FILE>;
close FILE;
# we haev teh virabiles now!@$ si teh l33t!!!!!1111oneoneone
@mail = split(/\,/,$mailaddresses);
foreach(@mail) {
$mailuser = $_;
$mailuser =~ s/\\//;
# I need new socks!
my $sock = new IO::Socket::INET (
PeerAddr => $mailserver,
PeerPort => $mailport,
Proto => 'tcp',
Timeout => '5'
);
# Do I have new socks now???!?!?!
if(!$sock) { die "Can't reach mailserver!\n"; } # Can't run without new socks!
print $sock "ehlo ik\r\n";
sleep(1);
sysread($sock, $buff, 1000);
print "$buff";
print $sock "mail from: big\@fake.nl\r\n";
undef($buff);
sleep(1);
sysread($sock, $buff, 1000);
print "$buff";
print $sock "rcpt to: $mailuser\r\n";
undef($buff);
sleep(1);
sysread($sock, $buff, 1000);
print "$buff";
print $sock "data\r\n";
print $sock "Subject: $subject $date\r\n";
foreach(@file) {
print $sock $_;
}
print $sock ".\r\n";
sleep(1);
close($sock);
}
the mail is send from the cron:
/root/update.sh>/root/output1 ; /root/meelskript.pl /root/meelskript1.cfg /root/output1 2>&1
I tried a lot of things but I can find it
Any help would be very great
Dirk
|