Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 22nd, 2012, 02:02 PM
dirk385 dirk385 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 dirk385 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #2  
Old November 22nd, 2012, 02:13 PM
OmegaZero OmegaZero is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: May 2007
Posts: 737 OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level)OmegaZero User rank is General (90000 - 100000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 1 m 12 sec
Reputation Power: 928
When you post code, place it between [code]...[/code] tags to keep it legible.

Your script prints out the responses from the server, have you looked at those to determine what is happening?

Is there any particular reason why you're using IO::Socket instead of a Net::SMTP or even better Mail::Transport::SMTP? Either of those would protect you from errors in the implementation of the protocol.

I don't see anything in your code to ensure the '.' that terminates the mail body will be preceded by a \r\n.
__________________
sub{*{$::{$_}}{CODE}==$_[0]&& print for(%:: )}->(\&Meh);

Reply With Quote
  #3  
Old November 22nd, 2012, 02:37 PM
dirk385 dirk385 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 2 dirk385 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 1 m 17 sec
Reputation Power: 0
The reason why we use IO::Socket is because of the following:

1) Someone else wrote the perl script ( i can not reach him)
2) I'm not that handy to program myself
3) The server is a sort appliance so not all the perl libraries are there, I think Net::SMTP; is on the system.
4)I do not know how the rewrite the script to use Net::SMTP

Thanks,
Dirk

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Perl mail script using use IO::Socket;

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap