The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Monitoring & emailing log files davidra UNIX for Dummies Questions & Answers 11 02-14-2008 06:36 PM
Multiple Files deletion in perl pulkit Shell Programming and Scripting 1 02-12-2008 05:55 AM
Copying files and emailing them out jhofilena Shell Programming and Scripting 1 12-18-2007 01:23 AM
Perl program to read from multiple files jyotipg Shell Programming and Scripting 1 07-19-2006 09:26 PM
Combining Multiple files in one in a perl script rahulrathod Shell Programming and Scripting 1 12-18-2005 01:51 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-11-2004
Tonka52 Tonka52 is offline
Registered User
  
 

Join Date: Feb 2004
Posts: 14
Perl - Emailing MULTIPLE files as attachment

Hi Guys,

I would love an example as to how I can send multiple files in one email using perl. The file types are .csv

I have read that mimencode is required? Is there any other way or is that it?

Thanks
  #2 (permalink)  
Old 02-11-2004
photon's Avatar
photon photon is offline
Registered User
  
 

Join Date: Jul 2002
Posts: 162
There is a very eloquent example in cookbook.

Code:
#!/usr/bin/perl -w
# mail-attachment - send files as attachments
 
use MIME::Lite;
use Getopt::Std;
 
my $SMTP_SERVER = 'smtp.example.com';           # CHANGE ME
my $DEFAULT_SENDER = 'sender@example.com';      # CHANGE ME
my $DEFAULT_RECIPIENT = 'recipient@example.com';# CHANGE ME  
 
MIME::Lite->send('smtp', $SMTP_SERVER, Timeout=>60);
 
my (%o, $msg);
 
# process options
 
getopts('hf:t:s:', \%o);
 
$o{f} ||= $DEFAULT_SENDER;
$o{t} ||= $DEFAULT_RECIPIENT;
$o{s} ||= 'Your binary file, sir';
 
if ($o{h} or !@ARGV) {
    die "usage:\n\t$0 [-h] [-f from] [-t to] [-s subject] file ...\n";
}
 
# construct and send email
 
$msg = new MIME::Lite(
    From => $o{f},
    To   => $o{t},
    Subject => $o{s},
    Data => "Hi",
    Type => "multipart/mixed",
);
 
while (@ARGV) {
  $msg->attach('Type' => 'application/octet-stream',
               'Encoding' => 'base64',
               'Path' => shift @ARGV);
}
 
$msg->send(  )
Include attached files when you run script.

Otherwise, you can do it the hard way.

Code:
#!/usr/bin/perl -w
 
use MIME::Lite; 

$msg = MIME::Lite->new( 
	From => 'you@yoursite.com', 
	To => 'you@yoursite.com', 
	Subject => 'Multiple attachments', 
	Type => 'multipart/mixed');
 
$msg->attach(	Type		=>'text/plain', 
		Path 		=>"/data/file1.csv", 
		Filename 	=>"file1.csv");

$msg->attach(	Type		=>'text/plain', 
		Path 		=>"/data/file2.csv", 
		Filename 	=>"file2.csv");

$msg->attach(	Type		=>'TEXT',
		Data		=>'Hello mom');
 

## Attach etc...

$msg->send();	#sendmail(1) or $msg->send('smtp', 'mailserver.yoursite.com');
I do not think there is another way then MIME.
  #3 (permalink)  
Old 02-11-2004
Tonka52 Tonka52 is offline
Registered User
  
 

Join Date: Feb 2004
Posts: 14
Thanks

That example should be fine!

Thanks Mate
  #4 (permalink)  
Old 02-11-2004
Optimus_P Optimus_P is offline Forum Advisor  
flim flam flamma jamma
  
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
or also in perl just use the back ticks and execute shell code from your perl command.

but yeah if you want to stay completely perl then one of the above is better.
Closed Thread

Bookmarks

Tags
perl, perl shift, shift, shift perl

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:03 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0