Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Help sending with MIME::Lite

by drock (Beadle)
on Sep 17, 2004 at 19:48 UTC ( #391882=perlquestion: print w/replies, xml ) Need Help??

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

I am using MIME Lite along with sendmail to sendmail when a file is greater than 0 bytes, but it is not actually sending the contents, but the rather the variable name which I understand why, but I want to send the actual data in the Data => line.
my $scratchtps="/usr/local/log/sctps"; sub mailme { my $msg = MIME::Lite->new( From => 'EDM01 <root@edm01.ohnet>', To => 'Derek Smith <dbsmith@ohiohealth.co +m>', Subject => "EDM Return Tapes", Data => $scratchtps ); $msg->send; } if ( -s $scratchtps ) { &mailme; }
thank you, derek

janitored by ybiC: Retitle from "MIME::Lite" because one-word nodetitles hinder site search

Replies are listed 'Best First'.
Re: Help sending with MIME::Lite
by waswas-fng (Curate) on Sep 17, 2004 at 20:22 UTC
    Try attaching the file:

    sub mailme { my $msg = MIME::Lite->new( From => 'EDM01 <root@edm01.ohnet>', To => 'Derek Smith <dbsmith@ohiohealth.com>', Subject => "EDM Return Tapes", Data =>"Hey here is your file!\n" ); $msg->attach(Type =>'image/gif', #whatever the MIME ty +pe is Path =>"$scratchps", Filename =>'scratchps', Disposition => 'attachment' ); $msg->send; } if ( -s $scratchtps ) { &mailme; }


    -Waswas
      sweetness, it is attaching the file but not the actual data with the file??? so I have an email with an attachment but when I open the attachment it contains my Data => "Here are you files today"
        err remove Data    =>"Hey here is your file!\n" so it looks like:
        sub mailme { my $msg = MIME::Lite->new( From => 'EDM01 <root@edm01.ohnet>', To => 'Derek Smith <dbsmith@ohiohealth.com>', Subject => "EDM Return Tapes" ); $msg->attach(Type =>'image/gif', #whatever the MIME ty +pe is Path =>"$scratchps", Filename =>'scratchps', Disposition => 'attachment' ); $msg->send; } if ( -s $scratchtps ) { &mailme; }


        -Waswas
Re: Help sending with MIME::Lite
by TedPride (Priest) on Sep 17, 2004 at 20:30 UTC
    You need to read the data into another variable and feed it instead of the file name. You can do this in a number of ways, including read and open / <INP> / close and so on, and this may not be the most efficient method due to my lack of experience, but here we go:
    my $scratchtps="/usr/local/log/sctps"; sub mailme { open (INP, $scratchtps) || die $!; my $content = join('', <INP>); close(INP); my $msg = MIME::Lite->new( From => 'EDM01 <root@edm01.ohnet>', To => 'Derek Smith <dbsmith@ohiohealth.com>', Subject => "EDM Return Tapes", Data => $content ); $msg->send; } if ( -s $scratchtps ) { &mailme; }
    Questions to ask:
    1. Is there a command for reading a file into a string variable?
    2. Is there a way to output an entire array without having to join first, as I'm doing above?
      Questions to ask:
      1. Is there a command for reading a file into a string variable?
      Well, there's File::Slurp, which is almost too simple to be a module... it's as easy as:
      my $contents = do { local (@ARGV,$/) = ($filename); <> };
      or other, less obfuscated ways, which all involve locally undefing the input record separator $/.

      2. Is there a way to output an entire array without having to join first, as I'm doing above?
      Not really... if you want to slap an array of strings together into one long string, that's what join is for. I mean, you could have a loop which concatenates the values together, but join is simpler and (I'm guessing) faster. Of course, as mentioned above, by setting $/ to undef, you won't divide the text up in the first place, so it wouldn't matter.
      ------------ :Wq Not an editor command: Wq
      not working, but thanks anyway!
Re: Help sending with MIME::Lite
by chanio (Priest) on Sep 18, 2004 at 22:02 UTC
    You could try using MIME::Lite::HTML that is the same PM that uses everybody that has a link "Send this News to a Friend".

    You just build an HTML page and send it complete!

    .{\('v')/}
    _`(___)' __________________________
    Wherever I lay my KNOPPIX disk, a new FREE LINUX nation could be established.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://391882]
Approved by sintadil
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2019-10-17 05:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?