Re: Sending files efficiently with Net::SMTP

2012-04-02 Thread Jenda Krynicky
From:   mailing lists 
> I have a perl (Ver. 5.10.0) program running over an old machine which send 
> messages with this code:
>
>
>     my $smtp = Net::SMTP->new($dstMailServer, Timeout=>10, Debug=>0,);
>     unless(defined($smtp)){
>     syslog LOG_INFO, "id:%s error: unable to connect with %s", $myid, 
> $dstMailServer;
>     exit $EX_TEMPFAIL;
>     }  
>     $smtp->mail($sender);
>     $smtp->to($recipient);
>     $smtp->data();
>     my $line;
>     open INPUTFILE, "<", $outfile or die "couldn't open $outfile";
>     while(defined($line=)){
>     $smtp->datasend($line);
>     }
>     close INPUTFILE;
>     $smtp->dataend();
>     $smtp->quit;
>
>
> since the machine belongs to a third party I have no possibility to
> install perl modules (no internet connection, compilers, etc) like
> Slurp. So sending files in the MB range is very slow. Anyone know how
> to optimize (if possible) this code?


Read (and send) the files by blocks (8kb sounds reasonable) instead
of lines.

See
perldoc -f read

not sure it'll help much though.

Jenda
= je...@krynicky.cz === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Sending files efficiently with Net::SMTP

2012-02-23 Thread Igor Dovgiy
Argh, misunderstood the doc a bit. This line in my code:

push @msg_content, "\r\n";

... is redundant, the termination string will be added automatically by
data() method.

-- iD

2012/2/23 Igor Dovgiy 

> From the documentation (http://perldoc.perl.org/Net/SMTP.html)
> ...
> data ( [ DATA ] ) - initiate the sending of the data from the current
> message. DATA may be a reference to a list or a list. If specified the
> contents of DATA and a termination string ".\r\n"is sent to the server. And
> the result will be true if the data was accepted.
> ...
>
> So maybe this'll speed it up a bit? Should go right after
> $smtp->to($recipient):
>
> ...
> open my $msg_fh, '<', $outfile
>   or die $!, "\n";
> my @msg_content = <$msg_fh>;
> close $msg_fh;
>
> push @msg_content, "\r\n";
> $smtp->data(\@msg_content)
>   or die 'Sending failed', "\n";
> ...
>
>
>
> -- iD
>
> 2012/2/23 mailing lists 
>
>> Hello all,
>>
>>
>> I have a perl (Ver. 5.10.0) program running over an old machine which
>> send messages with this code:
>>
>>
>> my $smtp = Net::SMTP->new($dstMailServer, Timeout=>10, Debug=>0,);
>> unless(defined($smtp)){
>> syslog LOG_INFO, "id:%s error: unable to connect with %s", $myid,
>> $dstMailServer;
>> exit $EX_TEMPFAIL;
>> }
>> $smtp->mail($sender);
>> $smtp->to($recipient);
>> $smtp->data();
>> my $line;
>> open INPUTFILE, "<", $outfile or die "couldn't open $outfile";
>> while(defined($line=)){
>> $smtp->datasend($line);
>> }
>> close INPUTFILE;
>> $smtp->dataend();
>> $smtp->quit;
>>
>>
>> since the machine belongs to a third party I have no possibility to
>> install perl modules (no internet connection, compilers, etc) like Slurp.
>> So sending files in the MB range is very slow. Anyone know how to optimize
>> (if possible) this code?
>>
>> --
>> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
>> For additional commands, e-mail: beginners-h...@perl.org
>> http://learn.perl.org/
>>
>>
>>
>


Re: Sending files efficiently with Net::SMTP

2012-02-23 Thread Igor Dovgiy
>From the documentation (http://perldoc.perl.org/Net/SMTP.html)
...
data ( [ DATA ] ) - initiate the sending of the data from the current
message. DATA may be a reference to a list or a list. If specified the
contents of DATA and a termination string ".\r\n"is sent to the server. And
the result will be true if the data was accepted.
...

So maybe this'll speed it up a bit? Should go right after
$smtp->to($recipient):

...
open my $msg_fh, '<', $outfile
  or die $!, "\n";
my @msg_content = <$msg_fh>;
close $msg_fh;

push @msg_content, "\r\n";
$smtp->data(\@msg_content)
  or die 'Sending failed', "\n";
...



-- iD

2012/2/23 mailing lists 

> Hello all,
>
>
> I have a perl (Ver. 5.10.0) program running over an old machine which send
> messages with this code:
>
>
> my $smtp = Net::SMTP->new($dstMailServer, Timeout=>10, Debug=>0,);
> unless(defined($smtp)){
> syslog LOG_INFO, "id:%s error: unable to connect with %s", $myid,
> $dstMailServer;
> exit $EX_TEMPFAIL;
> }
> $smtp->mail($sender);
> $smtp->to($recipient);
> $smtp->data();
> my $line;
> open INPUTFILE, "<", $outfile or die "couldn't open $outfile";
> while(defined($line=)){
> $smtp->datasend($line);
> }
> close INPUTFILE;
> $smtp->dataend();
> $smtp->quit;
>
>
> since the machine belongs to a third party I have no possibility to
> install perl modules (no internet connection, compilers, etc) like Slurp.
> So sending files in the MB range is very slow. Anyone know how to optimize
> (if possible) this code?
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


Sending files efficiently with Net::SMTP

2012-02-23 Thread mailing lists
Hello all,


I have a perl (Ver. 5.10.0) program running over an old machine which send 
messages with this code:


    my $smtp = Net::SMTP->new($dstMailServer, Timeout=>10, Debug=>0,);
    unless(defined($smtp)){
    syslog LOG_INFO, "id:%s error: unable to connect with %s", $myid, 
$dstMailServer;
    exit $EX_TEMPFAIL;
    }   
    $smtp->mail($sender);
    $smtp->to($recipient);
    $smtp->data();
    my $line;
    open INPUTFILE, "<", $outfile or die "couldn't open $outfile";
    while(defined($line=)){
    $smtp->datasend($line);
    }
    close INPUTFILE;
    $smtp->dataend();
    $smtp->quit;


since the machine belongs to a third party I have no possibility to install 
perl modules (no internet connection, compilers, etc) like Slurp. So sending 
files in the MB range is very slow. Anyone know how to optimize (if possible) 
this code?

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/