2009年4月24日星期五

[fw-core] What sort of speed should I expect from using Zend_Mail_Transport_Smtp with Gmail?

I have a script that sends an email out to a list of subscribers, but
it runs _really_ slow, especially for how few subscribers I am testing
against. Within the foreach loop, it takes about 3-5 seconds per
email.

My code looks something like this:

$config = array('ssl' => 'tls', 'port' => 587, 'auth' => 'login',
'username' => 'username', 'password' => 'password');
$smtpConnection = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $config);
Zend_Mail::setDefaultTransport($smtpConnection);

$attachment = new Zend_Mime_Part(file_get_contents($filepath));
$attachment->type = 'application/pdf';
$attachment->disposition = Zend_Mime::DISPOSITION_ATTACHMENT;
$attachment->encoding = Zend_Mime::ENCODING_BASE64;
$attachment->filename = $filename;

foreach ($subscribers as $subscriber) {
$message = new Zend_Mail('utf-8');
$message->setFrom('email@gmail.com', 'From Name')
->addTo($subscriber->email)
->setSubject($subject)
->setBodyText($body);
$message->addAttachment($attachment);
$message->send();
}

Is there something that I should be doing differently?

没有评论: