[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Perl sending e-mail

Posted on 2006-05-25
10
Medium Priority
?
265 Views
Last Modified: 2010-04-17
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;
0
Comment
Question by:marcparillo
  • 5
  • 5
10 Comments
 
LVL 57

Expert Comment

by:giltjr
ID: 16764810
What mail program are you using?
0
 
LVL 3

Author Comment

by:marcparillo
ID: 16765028
'usr/bin/sendmail'
0
 
LVL 57

Expert Comment

by:giltjr
ID: 16765757
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:marcparillo
ID: 16765843
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
 
LVL 57

Expert Comment

by:giltjr
ID: 16765965
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
 
LVL 3

Author Comment

by:marcparillo
ID: 16768561
Interesting --
It's a mix of domains -- so that would explain why some e-mails arrive faster than others.
0
 
LVL 57

Expert Comment

by:giltjr
ID: 16768649
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
 
LVL 3

Author Comment

by:marcparillo
ID: 16768797
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
 
LVL 3

Author Comment

by:marcparillo
ID: 16768847
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
 
LVL 57

Accepted Solution

by:
giltjr earned 2000 total points
ID: 16768913
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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Make the most of your online learning experience.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Progress

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question