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

Mail::Sender help

by blacksmith (Hermit)
on Sep 11, 2001 at 20:38 UTC ( [id://111774]=perlquestion: print w/replies, xml ) Need Help??

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

I can not seem to figure this out. I think the problem may have to do with references, and I need more knowledge of them. But, could I still get a leg up on this one? Please point me in the right direction of the answer. I am opening and using a file named "email.txt" that is formatted like this :
'him@here.com','C:/test1.txt','C:/test2.txt','C:/test3.txt' 'her@there.com','C:/test3.txt' 'it@where.com','C:/test2.txt','C:/test1.txt'

Some people may recall this from an earlier post I made. And, thanks for those replies by the way. They were most helpful.
Now I have this script :
#!c:/perl -w use Mail::Sender; my $time = localtime; my $subj_line = "Price Change Worksheet for $time"; my $work = 'me@work.com'; open(LIST, "c:/email.txt") or die $!; my @files; while(<LIST>) { s/^'//; s/'\n?$//; @files = split /','/, $_; my $email = shift @files; my $sender = new Mail::Sender( {smtp => 'mail.domain.com',from => $wor +k}) || die "$Mail::Sender::Error\n"; $sender->OpenMultipart( {to => $email, subject => $subj_line}); $sender->Body; $sender->SendLine('Here are the price change worksheets.'); $sender->SendFile( {description => 'Text File', encoding => 'Base64', file => @files}) and print "Mail was sent OK." || die "$Mail::Sender::Error\n"; $sender->Close; }

I am wondering how to attach all of the files listed for each individual email address into one email. I am just receiving an email with no attachments but at least I am getting the body message. The man page for Mail::Sender is located here.
Thanks.
Blacksmith.

Replies are listed 'Best First'.
Re: Mail::Sender help
by suaveant (Parson) on Sep 11, 2001 at 21:09 UTC
    it needs a ref to an array... file => \@files

                    - Ant
                    - Some of my best work - Fish Dinner

      I have tried that and still can not get it to work.

      file => \@files

      Could there be something wrong somewhere else? It sends the mail to each of the recipients and puts the text Here are the price change worksheets. into the body of the email. Just no attachments.
      Sorry for the previous message. I found the problem and have fixed it. You helped me greatly and I appreciate it.
      Blacksmith.
        Hehe, no problem... there is always a bigger and better error :)

                        - Ant
                        - Some of my best work - Fish Dinner

Re: Mail::Sender help
by drfrog (Deacon) on Sep 11, 2001 at 21:54 UTC
    what mail deamon are you using?

    there is a bug with mail::sender
    it does not work with attachements in qmail
    read the perldoc bug section for more


    back in the day we didnt have no old school

      This problem should be fixed in newest version.

      There were two problems in that code:

      • the "new Mail::Sender" doesn't return an undef in case it failed creating the object, but a negative error code. So you have to use either
        my $sender = new Mail::Sender (...); ref $sender or die "$Mail::Sender::Error\n";
        or
        my $sender = new Mail::Sender (...); $sender > 0 or die "$Mail::Sender::Error\n";
      • Pretty much the same holds for the Open() and OpenMultipart() methods. Actualy these two are more likely to fail than the object creation since at THIS point the module tries to connect to the server.
      • It's good that Blacksmith tests the result of SendFile(), but the mail is safely sent only if the $sender->Close() said all is OK as well. You can attach several files by several calls to SendFile() and the mail is finished only after you ->Close() it.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-23 23:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found