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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sending .txt attachment with sendmail...

Status
Not open for further replies.

spewn

Programmer
May 7, 2001
1,034
0
0
i'm using this basic code to email:

Code:
open (MAIL, "|/usr/sbin/sendmail -t") || return 0;
select (MAIL);
print << "EOF";
To: That Guy <email\@yoursite.com>
From: My Company <email\@mysite.com>
Subject: Heres that file
blah blah blah
EOF
close (MAIL);
select (STDOUT);

what i'm trying to do is send a text file along with this email...

i know i can accomplish this with MIME Lite, but how about with what i'm working with?

thanks!

- g
 
Here is an example:

Code:
my $attachment_fullpath = '';
open (LOG, "<$attachment_fullpath") || die "Cannot Open";
my @attachment_text = <LOG>;
close (LOG);

my $attachment_filename = "File.txt";

open (MAIL, "| /usr/sbin/sendmail -t >& /dev/null");
print MAIL qq~To: "$to" <$to>
From: "$from" <$from>
Subject: $subject
~;
print MAIL qq~MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="unique_boundary_string"\n\n~;
print MAIL qq~MIME Failed.\n~;
print MAIL qq~
--unique_boundary_string
Content-Type: text/plain; charset=us-ascii\n\n~;
print MAIL qq~$message~;
print MAIL qq~
--unique_boundary_string
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="$attachment_filename"\n\n~;
print MAIL qq~@attachment_text~;
print MAIL qq~
--unique_boundary_string--
~;
print MAIL qq~MIME Failed.~;
print MAIL qq~\n.~;
close(MAIL);

Chris
 
If you have MIME::Lite installed or can install it, it makes sending attachments a snap.

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

Part and Inventory Search

Sponsor

Back
Top