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!

perl script for file attachment

Status
Not open for further replies.

sigal

IS-IT--Management
Jan 29, 2004
3
AR
i am looking for a script that handle sending mail with file attachments (only txt file attachments)

thanks in advance
 
Get familiar with the perldocs. On a *nix system, you can do "perldoc perl" to get started. "perldoc -h" also works.

perldoc -q mail

gives back a lot of info - here is some of it:

---------------------------------------
=head2 How do I send mail?

Use the C<sendmail> program directly:

open(SENDMAIL, &quot;|/usr/lib/sendmail -oi -t -odq&quot;)
or die &quot;Can't fork for sendmail: $!\n&quot;;
print SENDMAIL <<&quot;EOF&quot;;
From: User Originating Mail <me\@host>
To: Final Destination <you\@otherhost>
Subject: A relevant subject line

Body of the message goes here after the blank line
in as many lines as you like.
EOF
close(SENDMAIL) or warn &quot;sendmail didn't close nicely&quot;;

The B<-oi> option prevents sendmail from interpreting a line consisting
of a single dot as &quot;end of message&quot;. The B<-t> option says to use the
headers to decide who to send the message to, and B<-odq> says to put
the message into the queue. This last option means your message won't
be immediately delivered, so leave it out if you want immediate
delivery.

Or use the CPAN module Mail::Mailer:

use Mail::Mailer;

$mailer = Mail::Mailer->new();
$mailer->open({ From => $from_address,
To => $to_address,
Subject => $subject,
})
or die &quot;Can't open: $!\n&quot;;
print $mailer $body;
$mailer->close();

The Mail::Internet module uses Net::SMTP which is less Unix-centric than
Mail::Mailer, but less reliable. Avoid raw SMTP commands. There
are many reasons to use a mail transport agent like sendmail. These
include queueing, MX records, and security.
---------------------------------------
The perldocs is you online local(to your system) source of perl information for your installation - they come with the standard perl installation.

HTH.
Hardy Merrill
Mission Critical Linux, Inc.
 
I assume B<-oi> was meant to bold that text? Use [ b ]-oi[ /b ] (without the spaces) for bold.

What was the C<sendmail> supposed to do?

Just curious.

(You can click on &quot;Process TGML&quot; after the checkbox at the bottom of the posting form to see all the available tags.) Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
I don't know what C<sendmail> is supposed to do - that's how it show's up in my perldocs - I'm working with perl, version 5.005_03. Basically when I present perldocs info, I just copy and paste right out of my telnet window into my tektips reply - everything is exactly as it appears in my telnet window. Not sure about the B<-oi> either.
Hardy Merrill
Mission Critical Linux, Inc.
 
Oh, that makes sense. Didn't know you did a cut-and-paste. It's probably intended to do something similar to TGML, but isn't quite doing what was intended. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top