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

Unix sendmail attachments

Status
Not open for further replies.

stevetrans140

Programmer
Joined
Jun 14, 2002
Messages
7
Location
CA
How do I attach files using sendmail?
 
This is a small chunk showing how I do it using uuencode. This has been clipped from a program and sanitized to remove some system specific stuff, but, hopefully it illustrates an approach.

Code:
# uuencode attachment to go with email
my $output_file = './templates/'.$session.'.txt';
`unix2dos $input_file | uuencode info.txt >$output_file`; 

# grab output_file as attachment to send with email
my $mail_buffer;
open(MDR,&quot;<$output_file&quot;) or showError(&quot;Failed to open MDR, $!&quot;);
while (<MDR>) { $mail_buffer .= $_; }
close MDR;

open (MAIL, &quot;|$sendmail -f NADA $recipient&quot;) || showError(&quot;Can't open $mail_prog!, $!&quot;);
print MAIL &quot;From: $recipient\n&quot;;
print MAIL &quot;Reply-To: $recipient\n&quot;;
print MAIL &quot;Errors-to: $recipient\n&quot;;
print MAIL &quot;Subject: New Metadata Record\n&quot;;
print MAIL &quot;Precedence: bulk\n\n&quot;;
print MAIL &quot;-----------------------------------------------------------\n&quot;;
print MAIL &quot;Your information is attached.\n&quot;;
print MAIL &quot;$mail_buffer\n&quot;;
close (MAIL);
'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top