Line # Revision Author
1 39 dpavlin #!/usr/bin/perl -w
2
3 #
4 # Usage:
5 #
6 # echo dpavlin@pliva.hr Dobrica Pavlinusic | ./send-bulk.pl
7 # echo first.last@pliva.hr | ./send-bulk.pl
8 #
9
10 my $debug=0;
11
12 my @emails;
13 my @fullnames;
14
15 use strict;
16
17 while (<>) {
18 chomp;
19
20 s/\015//g; # kill cr
21
22 tr/šðžèæŠÐŽÈÆ/¹ð¾èæ©Ð®ÈÆ/; # 1250 -> iso8859-2
23
24 s/^"//;
25 s/"$//;
26 s/\t"/\t/g;
27 s/"\t/\t/g;
28 s/ */ /g;
29
30 next if (/^#/ || /^$/ || /^\s+$/);
31
32 my ($email,$fullname);
33
34 if (m/^(\w+)\.([\w-]+)\@[.\w-]+$/) {
35 $fullname=ucfirst($1)." ".ucfirst($2);
36 $email=$_;
37 print "Heuristic: $_ -> $fullname <$email>\n" if ($debug);
38 } elsif (/\s/) {
39 ($email,$fullname)=split(/\s+/,$_,2);
40 } else {
41 $email = $_;
42 $fullname = "";
43 }
44
45 die "usage:\necho email\@dom first last name | $0\n[input: $_]\n" if (!defined($fullname) || !defined($email) || $email !~ m,@,);
46
47 push @emails,$email;
48 push @fullnames,$fullname;
49
50 }
51
52 print "Collected ",($#emails+1)," e-mail addresses...\nSending...\n";
53
54 foreach my $email (@emails) {
55 my $fullname = shift @fullnames;
56
57 if (defined $debug && $debug) {
58 open(MAIL,">> /tmp/mailfoo") || die "$!";
59 } else {
60 open(MAIL,"| /usr/lib/sendmail -t") || die "sendmail: $!";
61 }
62
63 my $in_mail="mail.txt";
64
65 open(IN,"$in_mail") || die "in mail: $!";
66 my $headers=1;
67 while(<IN>) {
68 # ship some of headers in outgoing mail
69 next if ($headers && (/^From / || /^Status: / || /^X-Mutt\S*: /));
70 $headers=0 if (/^$/);
71 chomp;
72 chomp;
73 if ($fullname && $fullname ne "") {
74 s/^To: ###email###.*$/To: $fullname <$email>/g;
75 } else {
76 s/^To: ###email###.*$/To: $email/g;
77 }
78 print MAIL "$_\n";
79 }
80 close(IN);
81 close(MAIL);
82 # print "." if ($debug);
83 print "$fullname <$email>\n";
84 }
85
86 1;
87
88 __END__
89
90 =head1 e-mail forge
91
92 this is strictly prohibited by netiquette
93
94 =head2 Create e-mail message using mail client in file mail.txt
95
96 e.g. Use mutt to create e-mail message and postpone it. Usage of mutt or some other mail client is recommended if you want to include attachements in your e-mail message. Otherwise, you can also use any editor (vi...). Then move file with postponed message to mail.txt and edit From: header so that it apperas as requested.
97
98 It should have at least following headers:
99
100 From: PCST happy support <pcst@pliva.hr>
101 To: ###email###
102 Subject: Happy, happy, joy, joy
103
104 body of message
105
106 Token ###email### is placeholder which will be replaced by full name of person and an e-mail address.
107
108 The script will automaticlly remove any From e-mail date header (which separates message in postponed messages folder), Status: headers which marks message as allready opened and X-Mutt header.
109
110 =head2 Create list of e-mail addresses for distribution
111
112 List should be in following format:
113
114 e-mail@domain.bla First Last name
115
116 e-mail address and First and last name must be whitespace (space, tab)
117 separated.
118
119 =head2 Start send-bulk.pl script
120
121 You should be in directory which has mail.txt (template mail), and list of e-mail addresses (list.txt in this example) and then do:
122
123 send-bulk.pl < list.txt
124
125 =head2 Having problems?
126
127 Optional step is to check if line
128
129 #my $debug=1
130
131 in send-bulk.pl is commeted (that's the # at beginning of the line), because if it isn't, it won't send any mails, just create temp file /tmp/mailfoo for debugging.
132
133 =cut