tony has asked for the wisdom of the Perl Monks concerning the following question:

Many thanks to chromatic btrott and even BBQ on my last post about getting a filehandle to write to with Mailer::Mail. I posted some additional info yesterday, but I fear no-one has seen it and we've moved to another page, so, just on the off-chance someone has some additional thoughts, herein the additional information:

I can print() to $mailer but I cannot write() to it.

Here are the errors.
Write on closed filehandle at ./format_eg.pl line 77. Write on closed filehandle at ./format_eg.pl line 78.
Lines 77 and 78 are the two write statements in the code below. The code works on STDOUT and a normal file. Here is the code.

sub Write_Data{ format STDOUT = @<<<<<<<<<<@<<<<<<<<<<<@<<<<<<<<<<<<@<<<<<<<<<<<<<<<<<<<<<< shift(@printrows), shift(@printrows), shift(@printrows), shift(@printrows) . my $To = 'dvmrgn@home.com'; my %mail_header = ('To', $To, 'From', 'webmaster@onlinerenter.com', 'Subject', 'Test of New Clients Report' +); my $mailer = new Mail::Mailer 'smtp', Server=>'smtp.telusplanet.net'; $mailer->open(\%mail_header); my $ofh = select($mailer); $~ = "STDOUT"; write ; write ; $mailer->close; select($ofh); } # End of write_data
There endeth the question, much thanks in advance if you have some insight/wisdom to share.

Replies are listed 'Best First'.
Re: More Mailer::Mail
by chromatic (Archbishop) on Apr 28, 2000 at 19:55 UTC
    There are two things to suggest here. First, try specifying 'test' instead of 'smtp': my $mailer = new Mail::Mailer 'test'; This will echo the output to your screen instead of actually sending it. Second, here's a warning from perlform:
    The lone dot that ends a format can also prematurely end a mail message passing through a misconfigured Internet mailer (and based on experience, such misconfiguration is the rule, not the exception). So when sending format code through mail, you should indent it so that the format- ending dot is not on the left margin; this will prevent SMTP cutoff.
    If 'test' works, you have a pretty good candidate for the second option.
Re: More Mailer::Mail
by tony (Initiate) on May 01, 2000 at 22:04 UTC
    chromatic,
    part one of your answer seems to work, but part two is causing some confusion.

    Dave writes:
    Ok, I tried 'test' for the mailer type everything worked. I could not get the indented dot on the format to work. Either incomplete format errors or the same old write to closed file handle error.

    If there is any example code on an indented format it would be appreciatted.

    I ended up writing the report to a temp file and then printing it into the mailer handle. Everything works like a charm. Inefficient, but it works Thanks to everyone There endeth the message. TIA