Since I did not find solution to the problem description here, I decided to use sysread
and syswrite
for dialog with smtp server. Below is my test code:
sub test {
my ($dbh) = @_;
my $server = "smtp.mail.ru";
my $ip = $server;
$ip = inet_aton($ip);
$ip = inet_ntoa($ip);
$ip = &ip2long($ip);
my $port = 465;
my $pid = 0;
my $is_ssl = 1;
my $answer;
my $user = 'my_mail@mail.ru';
my $buff = 8192;
if (&choose_proxy($ip, $port, $dbh, $pid)) {
if (&connect($ip, $port, $is_ssl, $pid, $server)){
data_read($buff);
my $ehlo = "ehlo mydomain.com\n";
data_send($ehlo);
data_read($buff);
my $auth = "auth login\n";
data_send($auth);
data_read($buff);
my $smtpuser = encode_base64($user);
my $smtppassword = encode_base64('password');
data_send($smtpuser);
data_read($buff);
data_send($smtppassword);
data_read($buff);
my $mail = "mail from: <$user>\n";
data_send($mail);
data_read($buff);
my $to = 'my_mail@mail.ru';
$to = "rcpt to: <$to>\n";
data_send($to);
data_read($buff);
my $start = "DATA\n";
syswrite($socket, $start, length($start));
data_read($buff);
my $data = "test message\n";
data_send($data);
my $end .= ".\n";
data_send($end);
data_read($buff);
my $quit = "quit\n";
data_send($quit);
data_read($buff);
return $socket;
}
}
}
sub data_send {
my $data = shift;
if ($debug_smtp) {
print ">> $data";
}
syswrite($socket, $data, length($data));
}
sub data_read {
my $buff = shift;
my $data;
sleep(1);
sysread($socket, $data, $buff);
if ($debug_smtp) {
print "<< $data";
}
}
I had a lot of questions and errors that I can't solve.
At first, sometimes! i get:Use of uninitialized value $data in concatenation (.) or string at ...
after end of data(data_send($end);
).
Secondly, data_send($end)
not working on Gmail, all this code not working on GMX.
Thirdly, code while {sysread($socket, $data, $buff);}
not work, and i use sleep(1)
, its bad.
Finally, i received file with headers and body of message, but syswrite
not work for variable that contains the file content.
I would be grateful for any help, thank you.
Here's my beta code, it works for most popular smtp server.