1 |
#!/usr/bin/perl -w |
#!/usr/bin/perl -w |
2 |
|
|
3 |
|
# send same message and different attachements to people. Run this script |
4 |
|
# without arguments to see usage, and customize message on top of script |
5 |
|
# |
6 |
|
# Dobrica Pavlinusic, http://www.rot13.org/~dpavlin/sysadmin.html |
7 |
|
|
8 |
use strict; |
use strict; |
9 |
use MIME::Lite; |
use MIME::Lite; |
10 |
|
|
11 |
|
# customize this part !! |
12 |
|
my $from = 'Joe Doe <joe.doe@nobody.com>'; |
13 |
|
my $subject = "New informations about..."; |
14 |
|
my $errors = 'postmaster@nobody.com'; |
15 |
|
my $body = "Please find attached more information about..."; |
16 |
|
# end of user configuration |
17 |
|
|
18 |
my %ext2mime; |
my %ext2mime; |
19 |
|
|
20 |
open(MIME,"/etc/mime.types") || die "mime.types: $!"; |
open(MIME,"/etc/mime.types") || die "mime.types: $!"; |
35 |
|
|
36 |
if (! $curr_dir) { |
if (! $curr_dir) { |
37 |
print "\nUsage: $0 [directory]\n\n"; |
print "\nUsage: $0 [directory]\n\n"; |
38 |
print "diretory should containt directories which are valid e-mail\n"; |
print "directory should containt directories which are valid e-mail\n"; |
39 |
print "addresses (like first.last\@pliva.com) and attachements inside\n"; |
print "addresses (like first.last\@pliva.com) and attachements inside\n"; |
40 |
print "that directory (directories without \@ will be ignored !!).\n"; |
print "that directory (directories without \@ will be ignored !!).\n"; |
41 |
print "All files in selected directory will be ignored.\n\n"; |
print "All files in selected directory will be ignored.\n\n"; |
76 |
closedir(DIR); |
closedir(DIR); |
77 |
|
|
78 |
my $msg = new MIME::Lite( |
my $msg = new MIME::Lite( |
79 |
From =>'Zeljko Covic <zeljko.covic@pliva.hr>', |
From => $from, |
80 |
To => $dir, |
To => $dir, |
81 |
Subject =>'Assessment Schedule', |
Subject => $subject, |
82 |
Type =>'multipart/mixed'); |
Type =>'multipart/mixed'); |
83 |
|
|
84 |
$msg->add('Errors-To' => 'Iva.Mladinic@pliva.hr'); |
$msg->add('Errors-To' => $errors); |
85 |
|
|
86 |
# debug |
# debug |
87 |
$msg->add('X-To' => $dir); |
$msg->add('X-To' => $dir); |
90 |
$nr++; |
$nr++; |
91 |
|
|
92 |
attach $msg ( |
attach $msg ( |
93 |
Type =>'TEXT', |
Type => 'TEXT', |
94 |
Data =>"Please find attached more information about the assessment with relevant files included."); |
Data => $body |
95 |
|
); |
96 |
|
|
97 |
foreach my $file (@files) { |
foreach my $file (@files) { |
98 |
|
|