On Fri, May 11, 2001 at 10:44:50AM +0100, Claire Downes wrote:
: I am retreiving data from the database and creating a text file which is
: then using the follwing command to e-mail to users :-
: `smtpmail user\@address.com take2.txt`;
: 
: If I vi the the created take2.txt file, the data is all there, present and
: correct.
: However, when I open the e-mailed file, not all of the data is there and
: it always cuts off at the same point. 
: I have calculated approximately how many characters there are up to the
: point at which the e-mailed file cuts off and it is approx 25600 chars !!! 
: The e-mailed file is only 28K, so that's not the problem.
: Does smtpmail do something strange with buffering ??
: Has anybody got any idea what the problem is & how to resolve it ?

Hmm, that is an interesting size limit issue.  I have never used
smtpmail so I don't know anything about it but, I have an idea that
will make your code work faster and exactly how you want it to.

There is a module on CPAN called Net::SMTP.  This is a beautiful
mailer, if you are using the DBI to connect and interact with your
database, the following sample code should help quite a bit.

use DBI;
use Net::SMTP;

my $dbh  = DBI->connect( 'dsn, etc.' );
my $smtp = Net::SMTP->new( 'smtp.foobar.com' );

$smtp->mail( '[EMAIL PROTECTED]' );

open BODY, "body.txt" or die $!;
my $body = do { undef $/; <BODY> }; # slurp the whole file
close BODY;

my $sth  = $dbh->prepare( "SELECT name, email FROM users" );

$sth->execute;
foreach my $user ( $sth->fetchall_array ) {
  $smtp->to( "'$users->[0]' <$user->[1]>" );
  $smtp->data( <<__END_OF_DATA__ );
Subject: Mail for $user->[0]

$body
__END_OF_DATA__

  $smtp->dataend;
}

$smtp->quit;

__END__

Basically, I read a file that will be the body of my email message,
then I get the name and email address of all my users from the
database and, while looping over my users, I send the email.

I hope this helps, and don't forget to read:

perldoc Net::SMTP

  Casey West

-- 
Shooting yourself in the foot with Powerbuilder 
While attempting to load the gun you discover that the LoadGun system
function is buggy; as a work around you tape the bullet to the outside
of the gun and unsuccessfully attempt to fire it with a nail. In
frustration you club your foot with the butt of the gun and explain to
your client that this approximates the functionality of shooting
yourself in the foot and that the next version of Powerbuilder will
fix it. 

Reply via email to