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

Fellow Monks: Hopefully this will be the last time I have to drive you all insane with
this question. Here is what I have coded so far:


use MIME::Lite; use Net::SMTP; $msg = MIME::Lite->new( From =>'root@mycompany.com', To =>'myname@mycompany.com', Subject =>'Summary Report', Type =>'multipart/mixed' ); $msg->attach( Type =>'TEXT', Filename =>'$rptname' ); MIME::Lite->send(smtp, "localhost"); $msg->send; exit 0;

I have to use a variable for the filename, since the actual name of
the report will have the date as part of it (i.e. summary2000-07-31).
And this program will be run every day, so it will generate a new report
for each day.

Any more help that you can all give will be greatly appreciated. Thank you
in advance.

TStanley

Replies are listed 'Best First'.
RE: Another MIME::Lite/Net::SMTP Question
by steveAZ98 (Monk) on Aug 01, 2000 at 01:32 UTC
    I beleive you have two problems. First the one mentioned above, about your single quoted filename, and second that you should be using Path instead of filename. The script below seems to work fine for me.
    #!/usr/bin/perl -w use MIME::Lite; use Net::SMTP; $msg = MIME::Lite->new( From =>'root@mycompany.com', To =>'me@home.com', Subject =>'Summary Report', Type =>'multipart/mixed' ); $msg->attach( Type => 'TEXT', Data => 'Test Message' ); $msg->attach( Type =>'TEXT', Path =>$path ); $msg->send('smtp','localhost'); exit 0;
    HTH
Re: Another MIME::Lite/Net::SMTP Question
by plaid (Chaplain) on Jul 31, 2000 at 23:26 UTC
    First of all: what's the question? I don't see what the problem is.

    One thing that sticks out as being incorrect is the line

    Filename =>'$rptname'
    In the $msg->attach function. The single quotes around $rptname will cause it to be interpreted literally, looking for an attachment called $rptname, instead of whatever the value of the variable is. You probably just want
    Filename => $rptname
Re: Another MIME::Lite/Net::SMTP Question
by Anonymous Monk on Aug 01, 2000 at 11:40 UTC
    did you check your mail-server ? maybe the problem is the smtp-server, not the script.....
Re: Another MIME::Lite/Net::SMTP Question
by Anonymous Monk on Aug 01, 2000 at 15:04 UTC
    Are you running SMTP on 'localhost'? Otherwise you might want to change 'localhost' to something being your mail relay.
Re: Another MIME::Lite/Net::SMTP Question
by TStanley (Canon) on Jul 31, 2000 at 23:40 UTC
    The problem comes down to the fact that the message is not
    sent.
Re: Another MIME::Lite/Net::SMTP Question
by TStanley (Canon) on Aug 01, 2000 at 18:12 UTC
    Taking the advice of plaid and steveAZ98, I removed the quotes from
    $rptname and changed "Filetype" to "Path". End result is I got exactly
    what I wanted. Bless all Perl Monks!

    Thomas Stanley
A living,breathing, fully-working MIME::Lite example
by princepawn (Parson) on Nov 03, 2000 at 19:04 UTC
    I looked through countless nodes yesterday for a truly working example of how to send attachments using MIME::Lite. Unfortunately, most people seemed content to post untried code. So after some aggravation, cursing, head-scratching, and whatever else, here is something that actually works because I just finished running it. Enjoy:
    use strict; use lib '/lnc/brannon/scripts/perl/lib/perl5/site_perl/5.6.0'; use MIME::Lite; my $msg = MIME::Lite->new ( From =>'brannon@lnc.usc.edu', To =>'princepawn@yahoo.com', Subject =>'A message with 2 parts...', Type =>'multipart/mixed' ); ### Add parts (each "attach" has same arguments as "new"): $msg->attach ( Type =>'TEXT', Data =>"Here's the JPEG file you wanted" ); $msg->attach ( Type =>'image/jpeg', Path =>'/lnc/brannon/public_html/pix/me/36.jpg', ); $msg->send('smtp','lnc.usc.edu');

      I'm not sure you looked hard enough. Check out RE: sending email. This script is used every day from a cron job and it's been tested under Linux and NT, which basically passes for cross-platform these days :)