Link to home
Start Free TrialLog in
Avatar of marcparillo
marcparillo

asked on

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;
Avatar of giltjr
giltjr
Flag of United States of America image

What mail program are you using?
Avatar of marcparillo
marcparillo

ASKER

'usr/bin/sendmail'
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
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?
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.
Interesting --
It's a mix of domains -- so that would explain why some e-mails arrive faster than others.
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).
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;
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;

ASKER CERTIFIED SOLUTION
Avatar of giltjr
giltjr
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial