Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email attachment using sendmail

Status
Not open for further replies.

youthman

Programmer
Apr 28, 2004
49
US
Good afternoon Gurus!
I am trying to write a script that will use sendmail to upload an email attachment and send it. Sending the email through perl using sendmail is easy enough, but can someone explain how to tweak the code to include an email attachment?
Here is my code so far . . .
Code:
$sendmail="/usr/lib/sendmail.sendmail -oi -t";
 print "starting . . .";

 $form_subject="testing";
 $form_message="I am now testing the email system for the attachment  Hopefully this will actually work.";

 $subject = "$form_subject";
 $body = "$form_message";
 open(MAIL, "| $sendmail") or die "Cant open Sendmail";
    print MAIL "To: $to\n";
    print MAIL "From: $from\n";
    print MAIL "Reply-to: $from\n";
    print MAIL "Subject: $subject\n\n";
    print MAIL "$body";
 close MAIL;

print "Your e-mail has been sent!";
exit;

Can anyone help with this?

Thanks
 
Make your life easier, use the MIME::Lite module if it is installed. Most hosts do have it installed.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
I have already pursued that option. . . It appears to be installed, but not correctly. Here is the script that I have for that:
Code:
use MIME::Lite;

$msg = MIME::Lite->new(From    => 'markn@indyhomevalues.com',
                       To      => '$to',
                       Subject => 'My File Tester',
                       Type    => 'multipart/mixed');

$msg->attach(Type        => 'TEXT',
             Path        => '/cgi-bin/mail/useless.txt',
             Filename    => 'useless.txt',
             Disposition => 'attachment');

$msg->send( ); 

print "<BR>it's been sent<BR>";
exit;

Here is what the server comes back with:
Can't locate Email/Date/Format.pm in @INC (@INC contains: /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.3/i386-linux-thread-multi /usr/lib/perl5/site_perl/5.8.6 /usr/lib/perl5/site_perl/5.8.5 /usr/lib/perl5/site_perl/5.8.4 /usr/lib/perl5/site_perl/5.8.3 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.4/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.3/i386-linux-thread-multi /usr/lib/perl5/vendor_perl/5.8.6 /usr/lib/perl5/vendor_perl/5.8.5 /usr/lib/perl5/vendor_perl/5.8.4 /usr/lib/perl5/vendor_perl/5.8.3 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.6/i386-linux-thread-multi /usr/lib/perl5/5.8.6 .) at /usr/lib/perl5/site_perl/5.8.6/MIME/Lite.pm line 1097.

Any ideas as to how to fix this? or just use the other code?
 
Actually, I was able to get the dependancies resolved . . . now, when I send the mail with the attachment, nothing shows up on the other end, even though the script completes with no errors. Any ideas on that?
 
Never mind! I got it fixed! THANKS ALL!

No more help is needed on this thread!

youthman
 
single-quotes where there should be none:

Code:
To      => '$to',

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top