DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone >

Simple Command-line Mailinglist

Snippets Manager user avatar by
Snippets Manager
·
Jan. 17, 07 · · Code Snippet
Like (0)
Save
Tweet
493 Views

Join the DZone community and get the full member experience.

Join For Free
This 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.

Popular on DZone

  • How to Hash, Salt, and Verify Passwords in NodeJS, Python, Golang, and Java
  • Choosing Between GraphQL Vs REST
  • Application Scalability — How To Do Efficient Scaling
  • Making Machine Learning More Accessible for Application Developers

Comments

Partner Resources

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo