Solved

How to speed up email sending through sendmail?

Posted on 2006-10-28
5
1,563 Views
Last Modified: 2013-12-17
Hi Everyone,

I have written a PHP script which retrieves my customers from MySQL database (around 10,000 customers) and sends them an email. The problem is, it sends emails with around 5 emails per second. But I know that others are able to send with around 20 emails per second.

PHP script simply sends through local MTA with mail() function in every member loop. Example:

mail('recipient@email.com', 'subject', 'body', 'headers');

What can be done in sendmail configuration to speed up the delivery?
0
Comment
Question by:blacklord
  • 2
5 Comments
 
LVL 8

Expert Comment

by:nitadmin
ID: 17826021
The speed at which e-mails are sent depends on how quickly or how fast smtp daemon can resolve MX records and whether it can connect to recipient smtp server to to transfer the e-mail.

I suggest that you setup your own DNS server and configure sendmail to use your internal DNS server to resolve MX records and A records.

Another thing you should know. Today there are many methods and tools (both software, hardware, and other services) that System administrators can use to block or reduce UCE (spam). These methods and tools can definately slow down, or completely block your SMTP server from connecting and transfering e-mails.

You could also create and configure multiple smtp daemons to handle the e-mails. This method could achieve your objective of sending 20 e-mails per second.

Cheers,
NITADMIN
0
 

Author Comment

by:blacklord
ID: 17832794
Hello NITADMIN,

I have 4500 opt-in email addresses on my website database. In order to see if the bottle-neck was my newsletter software or not, I wrote a small PHP script which retrieves all those 4500 members and sends them email. Here is the PHP code:

--------------
$SQLQuery = "SELECT * FROM websitemembers";
$ResultSet = mysql_query($SQLQuery);

$TotalMembers = mysql_num_rows($ResultSet);

$StartTime = strtotime(date('Y-m-d H:i:s'));
$IntervalStartTime = $StartTime;

$IntervalLoopAmount      = 50;
$IntervalCounter      = 0;
$TMPCounter                  = 0;

while ($EachMember = mysql_fetch_assoc($ResultSet))
      {
      $TMPCounter++;
      $IntervalCounter++;

      if (mail($EachMember['Email'], 'Test Subject - Custom Script', 'Test Body', 'From: cem@octeth.com') == false)
            {
            print "<span style='color: #ff0000;'>[FAILED]".$EachMember['Email']."</span><br>";
            }
      else
            {
            print "Email sent to ".$EachMember['Email']."<br>";
            }

      if ($IntervalCounter == $IntervalLoopAmount)
            {
            $IntervalCounter = 0;
            
            $IntervalFinishTime = strtotime(date('Y-m-d H:i:s'));

            $IntervalDuration = $IntervalFinishTime - $IntervalStartTime;

            $IntervalPerformance = number_format(($IntervalLoopAmount / ($IntervalDuration == 0 ? 1 : $IntervalDuration)), 1);

            print ("<h2>Interval Duration: ".$IntervalDuration." seconds - Total Performance: ".$IntervalPerformance." emails / second</h2>");
            
            $IntervalStartTime = strtotime(date('Y-m-d H:i:s'));
            }
      }

$FinishTime = strtotime(date('Y-m-d H:i:s'));

$TotalDuration = $FinishTime - $StartTime;

$TotalPerformance = number_format(($TotalMembers / $TotalDuration), 1);

print ("<h1>Total Duration: ".$TotalDuration." seconds - Total Performance: ".$TotalPerformance." emails / second</h1>");

exit;

--------------

As you can see, this script simply retrieves all 4500 members and loops them to send out emails. I only added benchmark codes inside the loop. When I execute this script, I noticed that the bottle-neck is not my PHP script. Because the sending performance of this simple PHP script was 11.6 emails per second which is quite low for such a simple script.

So, I think that the bottle-neck is the qmail (or sendmail) while accepting the email from php script via mail() function.

What can be the problem? Is qmail (or sendmail) resolving MX records of the recipient email address while accepting it from php script? If yes, how can this be disabled?

What do you suggest? My server is a powerful server so I don't believe that the speed-down will be because of my server.

Thanks for all your help! I feel that we are closer to the solution :)

0
 
LVL 8

Accepted Solution

by:
nitadmin earned 500 total points
ID: 17847739
Dear Blacklord,

You did not read my comments above very carefully, and you certainly do not understand what I wrote.

You program is fine. It will excute very quickly no matter how fast your processor(s) are or how much RAM you have.

The issue is that your MTA (mail transfer agent) which is either sendmail or qmail, has to detmine the ip address of the mail server for each recipient. It will have to query the DNS server twice, (once to query the mx record and second to query the ip address of host server) After this is done, it will have to create a tcp connection to the mail server, conduct  a brief handshaking procedure with the other server and finnaly transfer your e-mail. (that is if the other server does not reject your connection). This is a very slow process, no matter how fast you processor(s) are, or how much much memory you have, or how fast your internet connection is. This is smtp protocol you have to accept. It is slow, and in my opinion an ineffient  and insecure protocol.

What I can suggest you should is that you could configure and setup multiple SMTP damons to transfer your e-mails. This will be allow you to send more e-mail simutaneously.

Cheers,
NITADMIN
0

Featured Post

Do email signature updates give you a headache?

Constantly trying to correctly format email signatures? Spending all of your time at every user’s desk to make updates? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today!

Join & Write a Comment

When it comes to providing great business solutions, IBM and Microsoft are the two top companies excelling in the art. Both launch similar products aimed at a wide audience set and have a good customer satisfaction rate. Since their products are qui…
Resolve DNS query failed errors for Exchange
In this video we show how to create a Shared Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Sha…
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now