Add an 'attachment' for an Email script

I got a nice little script from tintin a while ago.

I wanted to add provisions to include an attachment. I've spent the last hour-and-half trying to figure what to do based on all the  examples I've looked at on line.

I'd really appreciate any help

Thanks-

*************************************************
Code's below
*************************************************
#!/usr/local/bin/perl

$at="\@ford.com";

open MAIL,"|/usr/lib/sendmail -t -oi" or die "Can not run sendmail $!\n";

print  MAIL<<EOF;

To:tmccar10$at
CC:tmccar10\@ford.com
From: tmccar10\@ford.com

Subject: Weekly Graphs

Attached are the graphs reflecting Ciscso Report


EOF

close MAIL;
tmccar10Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
use MIME::Lite;
0
tmccar10Author Commented:
Looks like I have a problem with the module, or maybe I just did it wrong.

Can you take a look and let me know?

Is there another way to do this, is this is the problem?

Thanks

*******************************
#!/usr/local/bin/perl

use MIME::Lite;

$at="\@ford.com";

open MAIL,"|/usr/lib/sendmail -t -oi" or die "Can not run sendmail $!\n";

print  MAIL<<EOF;

To:tmccar10$at
CC:tmccar10\@ford.com
From: tmccar10\@ford.com
.
.
.
$msg->attach (
   Type => 'application/pdf ',
   Path =>  /export/ford/eccws7/u/mso/www.86.80/fcsd/psl/namer/partadv/pdf,
   Filename => mgrchart.pdf,
   Disposition => 'attachment'
) or die "Error adding $file_gif: $!\n";



EOF

close MAIL;

###############################

> graphnote.cgi
Bare word found where operator expected at /usr/local/lib/perl5/site_perl/MIME/"
Bareword "co" not allowed while "strict subs" in use at /usr/local/lib/perl5/si.
Bare word found where operator expected at /usr/local/lib/perl5/site_perl/MIME/"
Bareword "co" not allowed while "strict subs" in use at /usr/local/lib/perl5/si.
syntax error at /usr/local/lib/perl5/site_perl/MIME/Lite.pm line 372, near "m{\"
BEGIN failed--compilation aborted at graphnote.cgi line 3.


0
TintinCommented:
There's loads of examples with MIME::Lite

What you need to do is:

#!/usr/local/bin/perl
use strict;
use MIME::Lite;

my $email = 'tmccar10@ford.com';

my $msg = MIME::Lite->new (
        From    => $email,
        To      => $email,
        Cc      => $email,
        Subject => 'Your subject',
);

$msg->attach (
  Type => 'application/pdf ',
  Path =>  /export/ford/eccws7/u/mso/www.86.80/fcsd/psl/namer/partadv/pdf,
  Filename => mgrchart.pdf,
);

$msg->send or die "Can not send email $!\n";
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

ozoCommented:
Although your usage of MIME::Lite was not the correct way to send an attachment, it should not have caused the errors you were seeing.
It looks like there was also a problem with the way /usr/local/lib/perl5/site_perl/MIME/Lite.pm  was installed.
Could you show the complete error messags?  The ones you posted seem to have been cut off at 80 characters.
0
tmccar10Author Commented:
Thanks

Looks like ozo is right.

After running tintin's script the same message popped.

Looks like a problem with the copy of MIME we have.

I commented out the 'USE strict', since it was mentioned in the error message. (below)

*********
Bare word found where operator expected at /usr/local/lib/perl5/site_perl/MIME/"
Bareword "co" not allowed while "strict subs" in use at /usr/local/lib/perl5/si.
syntax error at /usr/local/lib/perl5/site_perl/MIME/Lite.pm line 372, near "m{\"
BEGIN failed--compilation aborted at graphnote1.cgi line 3.
*********
I'm not sure where to go fropm here.

Thanks
0
ozoCommented:
If you could see the rest of the error messages to see the line numbers that may give more of a clue what's wrong.  It may be as simple as a misplaced quotation mark.
Or you might just want to try re-installing MIME::Lite
I don't see any "m{\" near line 372 in $MIME::Lite::VERSION 3.01
I see "m{\G" on lines 493, 495, 497, 497
0
ozoCommented:
Another alternative to MIME::Lite may be MIME::Entity
0
tmccar10Author Commented:
Thanks ozo,

If you're seeing 4 lines starting with "Bare word found where operator..." and ending with "...compilation aborted at graphnote.cgi line 3.", your seeing everything that I see.

I don't imagine that I can simply replace "Lite" with "Entity", couldn't be that straight forward.

I don't have control over PERL here, I guess if that's what's wrong I've gotta got through the server folks. I work at a major Ford operation...this will be interesting.  

Thanks again

0
ozoCommented:
If you're always generating mails with the same format, the only non-trival part looks like the base64 encoding, which you could learn how to do from the MIME::Lite source, or ask one of us to write it for you.
But even if you don't hve control over /usr/local/lib/perl5/site_perl/MIME
you could still install MIME/Lite.pm on your own directory and
use lib '.';
 
0
ozoCommented:
Is your terminal output truncating lines at 80 characters?
Could you either tell your terminal to wrap, or redirect the error messages with either
graphnote.cgi 2> errlog
(in  sh, ksh, bash, ...)
or
graphnote.cgi >& errlog
(in csh, tcsh, ...)
they should look more like
Bare word found where operator expected at /usr/local/lib/perl5/site_perl/MIME/Lite.pm line 123, near "$foo bar"
0
tmccar10Author Commented:
Thanks ozo-

That's what I like about EE--especially the PERL people--you folks know EVERYTHING. I, on the other hand, face PERL code about three times a year...not the best learning model

Anyway, here the COMPLETE error message:

Bare word found where operator expected at /usr/local/lib/perl5/site_perl/MIME/L
ite.pm line 372, near "m{\G\s*\Z}gco"
Bareword "co" not allowed while "strict subs" in use at /usr/local/lib/perl5/sit
e_perl/MIME/Lite.pm line 372.
Bare word found where operator expected at /usr/local/lib/perl5/site_perl/MIME/L
ite.pm line 374, near "m{\G$SEP$PHRASE\s*<\s*($ADDR)\s*>}gco"
Bareword "co" not allowed while "strict subs" in use at /usr/local/lib/perl5/sit
e_perl/MIME/Lite.pm line 374.
syntax error at /usr/local/lib/perl5/site_perl/MIME/Lite.pm line 372, near "m{\G
\s*\Z}gco"
BEGIN failed--compilation aborted at graphnote1.cgi line 3.



Thanks!
0
jmcgOwnerCommented:
Could you tell us what version of Perl you're running? (perl -v or perl -V should tell you) Is it still 5.003?

The error messages make it appear that your Perl interpreter is so old that it does not recognize the "c" modifier in the substitute operator. This change occurred somewhere between the 5.000 and 5.005 releases, as best I can tell. Of course, Mime:::Lite ought to have a require statement up front to more clearly document that it is dependent on a more recent version of Perl.

The "best" fix would be if you could get your system admins to update Perl to something newer.
0
ozoCommented:
$MIME::Lite::VERSION = "3.01" does have a
require 5.004;
If the compilation didn't get aborted by the co, you'd probably see an error from the require.
0
ozoCommented:
If you have Mail::Address the sub that uses the /c modifier does not appear to be used at all.
Perhaps you can just remove it.
0
tmccar10Author Commented:
As I said, you guys know everything!!!

We're running  perl 5.003

I'll ask out tech folks about this.

I'll get back to everybody then.

Is there an alternative if they give me any grief?

Thanks again for all the advice
0
TintinCommented:
Can't believe that people are still running 5.003 on production systems.  5.003 is absolutely ancient now.
0
tmccar10Author Commented:
I contacted our web server folks.

It can't be the cost!

I hope, maybe that once somebody asks, they update...but I'm not hopeful.

I'll see if I get an answer tomorrow.

Thanks Tintin


0
tmccar10Author Commented:
My fault, I guess. They update fairly regularly, but you need to change version paths with each new version, the default is to the oldest (5003).
(I'm kicking up the points, you folks have spent alot of time on me)

I've got the right path now, but I get this message, and I can't see anything obvious, unless "export" is somehow a key word, or something

########################################################
Bareword found where operator expected at graphnote1.cgi line 19, near "/export/ford"
        (Missing operator before ford?)
syntax error at graphnote1.cgi line 19, near "/export/ford"
########################################################

**************************
$msg->attach
 (
  Type => 'application/pdf ',
  Path =>  /export/ford/eccws7/u/mso/www.86.80/fcsd/psl/namer/pslplan/partadv/pdfs,
  Filename => mgrchart.pdf,
);
**************************

Thanks
0
ozoCommented:
 Path =>  '/export/ford/eccws7/u/mso/www.86.80/fcsd/psl/namer/pslplan/partadv/pdf',
  Filename => 'mgrchart.pdf',
0
tmccar10Author Commented:
That took care of that--I thought I tried the single quotes before I wrote...

I delayed coming back because I got an error message I was trying to clear myself:

"no data in this part
 at graphnote1.cgi line 25"

25. ($msg->send or die "Can not send email $!\n";)

I tried using different pdf files, move them to the same directory and the perl program...I couldn't get past "no data". I looked on the web and could only fine that it was a problem, but not a reason or a way to fix it.

The mail sends, NOT the attachment.


Thanks
0
ozoCommented:
You probably had a $msg->attach without a Path or Data
or a MIME::Lite->new without a Path or Data or Type =>'multipart/mixed'

my $msg = MIME::Lite->new (
        From    => $email,
        To      => $email,
        Cc      => $email,
        Subject => 'Your subject',
        Type    =>'multipart/mixed',
);
$msg->attach
 (
  Type => 'application/pdf ',
  Path =>  '/export/ford/eccws7/u/mso/www.86.80/fcsd/psl/namer/pslplan/partadv/pdfs',
  Filename => 'mgrchart.pdf',
);
print $msg->as_string;

or

my $msg = MIME::Lite->new (
        From    => $email,
        To      => $email,
        Cc      => $email,
        Subject => 'Your subject',
  Type => 'application/pdf ',
  Path =>  '/export/ford/eccws7/u/mso/www.86.80/fcsd/psl/namer/pslplan/partadv/pdfs',
  Filename => 'mgrchart.pdf',
);

or

my $msg = MIME::Lite->new (
        From    => $email,
        To      => $email,
        Cc      => $email,
        Subject => 'Your subject',
        Data => "Here's the PDF file you wanted"
);
$msg->attach
 (
  Type => 'application/pdf ',
  Path =>  '/export/ford/eccws7/u/mso/www.86.80/fcsd/psl/namer/pslplan/partadv/pdfs',
  Filename => 'mgrchart.pdf',
);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tmccar10Author Commented:
Finally!!

Learned a lot this time. As usual, more than I expected.

Adding the Data => seemed to do it.

Still have a problem with opening the file in Adobe.
"...it was sent as an email attachment and wasn't decoded correctly"....more to learn.

If you know a quick answer I'll take it, but I'm letting everyone go, you've done plenty!

Thanks for sticking with me, you've all got great patience.

Thom

0
TintinCommented:
What email client are you using to read the email?
0
tmccar10Author Commented:
Thanks -

I'm using Outlook.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.