Simple Command-line Mailinglist
Join the DZone community and get the full member experience.
Join For FreeThis code reads an email-list stored in the file"emailist.txt".
This file contains all adresses delimited by "\n", i.e.
one column of emails. However, you have to have sendmail installed.
#!/usr/bin/perl
#
# Mailing-List.pl
# 2005 by Sascha Tayefeh
# http://www.tayefeh.de
#
# This code reads an email-list stored in a file: emailist.txt
# This file contains all adresses delimited by \n, i.e.
# one column of emails.
#
use strict;
my ($absender, $empfaenger, $betreff, $body, $content,$file,$line,$i,$k);
my (@line,@liste);
$file="./emailist.txt"; # a one-column textfile providing the emails (one per line)
#$empfaenger = "singleReceiver\@singleReceiver.single"; # E-mail of a single-receiver
$absender = "sender\@sendersEmail.sender>"; # E-mail of the sender
$betreff = "Header here"; # header of the email
$body = "\nThis is the body of the messag \n\n Bye\n"; # The message body
$line[0]= sprintf("From: %s \n",$absender);
$line[1]= sprintf("To: %s \n",$empfaenger);
$line[2]= sprintf("Subject: %s \n",$betreff);
$line[3]= sprintf("%s \n",$body);
$i=0;
open(LIST, $file);
while (defined ($line=)) {
chomp $line;
$liste[$i] = $line;
$i++;
}
close(LIST);
print $body;
printf("%d emails to sent\n",$i);
for ($k=0; $k<$i; $k++) {
open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq") or die "fork fuer sendmail fehlgeschlagen: $!\n";
$line[1]= sprintf("TO: %s \n",$liste[$k]);
printf("Sending mail %d to %s\n",$k+1,$liste[$k]);
foreach $content (@line) {
print SENDMAIL $content;
}
close(SENDMAIL) or warn "sendmail wurde nicht recht beendet...";
sleep 1;
}
Opinions expressed by DZone contributors are their own.
Comments