Perl sending e-mail

What is the best way to send the same e-mail message to a defined list of e-mail addresses?

The script below only seems to work with two e-mail addresses.  If I add a third, the e-mail script doesn't work -- only one recipient gets the e-mail.  

Can you explain what could be wrong with the $recipient variable containing a list of e-mail addresses?  Should they be separated by commas or wrapped in double-quotes instead of single quotes?  I've tried different variations but I can't seem to get it to work with more than two e-mail addresses. Ugh!

open(FILE,"surveyresults/results.txt");
@indata = <FILE>;
close(FILE);
foreach $i (@indata) {
$reply .= $i;
}

$recipient = 'email1@mydomain.com; email2@mydomain.com; email3@mydomain.com';

open (MAIL, "|$mailprog -t -oi") || die "Can't open mail program\n";
print MAIL "To: $recipient\n";
print MAIL "From: Me\n";
print MAIL "Subject: Survey\n";
print MAIL "Content-type: text/plain;\n\n";
print MAIL "$reply";
print MAIL "\n\n";
close MAIL;
exit;
LVL 3
marcparilloAsked:
Who is Participating?
 
giltjrCommented:
What error are you getting?

Speed and reliability are based on so many factors it is almost useless to look at.

Take a look at reliability.  Most e-mail servers out of the box are configured to send delayed e-mail notices if it can't send the e-mail out after 24 hours and undeliverable after 5 days.

Speed:  Say you send me e-mail.  This depends on, busy your e-mail server is, your link to the Internet, your ISP's internal network, the connetion between your ISP and my ISP, my ISP's internal network, my link to the Internet, and how busy my e-mail server is.  I have not even mentioned that you may have a intermediatary e-mail gateway that your outbound e-mail may have to pass through, or that I may have a inbound e-mail gateway that all inbound e-mail must pass through.
0
 
giltjrCommented:
What mail program are you using?
0
 
marcparilloAuthor Commented:
'usr/bin/sendmail'
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
giltjrCommented:
I could not get two to work with semi-colons seperating the e-mail addresses.  I had to use comma's, so you may want to try:


     $recipient = 'email1@mydomain.com,  email2@mydomain.com, email3@mydomain.com';

in fact I got an error message when using semi-colons
0
 
marcparilloAuthor Commented:
You're right, commas work over semi-colons.  But what I'm discovering is when the e-mail is sent to one recipient, the message gets sent quickly, in a matter of seconds.  When you add just two more names to the list, it takes up to five minutes for the e-mails to go through.  Is this common or should there be no delay?
0
 
giltjrCommented:
Are all of the e-mail address to users within the same domain or are they different domain?

What are you measuring?  Most e-mail clients poll the e-mail server every so many minutes.  So if you were to send e-mail to 3 different people within the same e-mail domain, the e-mail may appear to arrive at different time based on when each users e-mail client checks to see if there is any new e-mail.

Example:  I use Mozilla as my e-mail client and I have it configured to check for new e-mail every 10 minutes, so if you were to send me e-mail 1 second after Mozilla check, it will appeare to me as if it took 9 minutes and 59 seconds for your e-mail to get to me.
0
 
marcparilloAuthor Commented:
Interesting --
It's a mix of domains -- so that would explain why some e-mails arrive faster than others.
0
 
giltjrCommented:
Yes.  Think of it this way, it is "mail".  Say you send out 3 letters to 3 different people in 3 different locations.  Will they all arrive at the same time?  No.

Now if they were all within the same domain it would be more like sending 3 letters in a single envlope.  The envolope would arrive at the location at the same time, but the 3 people may actually see it at differnt times based on when somebody delivers the indvidual letters (like each person e-mail client checking for new mail).
0
 
marcparilloAuthor Commented:
That's a great way of explaining it, thanks.

I've been testing the speed and reliability of e-mail with this simple script -- does it look right to you?

my $recipient = "myemailaddress\@earthlink.net";
$mailprog = '/usr/sbin/sendmail';
open (MAIL, "|$mailprog -t -oi") || print "Can't open mail program\n";
print MAIL "To: $recipient\n";
print MAIL "From: News Channel\n";
print MAIL "Subject: Archives Request Confirmation\n";
print MAIL "Content-type: text/plain;\n\n";
print MAIL "Testing E-mail";
print MAIL "\n\n";
close MAIL;
0
 
marcparilloAuthor Commented:
THIS SCRIPT RETURNS AN ERROR

#!/usr/bin/perl

$mailprog = '/usr/sbin/sendmail';

$recipient = 'myemail@address.com';
open (MAIL, "|$mailprog -t -oi") || die "Can't open mail program\n";
print MAIL "To: $recipient\n";
print MAIL "From: Test\n";
print MAIL "Subject: Test\n";
print MAIL "Content-type: text/plain;\n\n";
print MAIL "Testing";
print MAIL "\n\n";
close MAIL;

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.