如何提高发送安全 SMTP 电子邮件的速度?

How can I increase the speed of sending Secure SMTP emails?

我在使用 Exim 4.87 的服务器上有一个 PHPMailer 5.2.16,它也有一个用于安全连接的 TLS 证书。

我的PHP是这样的:

class MailerSMTP extends PHPMailer {
    /***
     * Mailer for authenticated SMTP  emails using account mail system
     ***/
    public function __construct(){
        $this->AddReplyTo('...', '...');
        $this->setFrom('...', '...');
        $this->Host = "hostname.co.uk";
        $this->isSMTP();
        $this->Timeout = 20;

        $this->SMTPAuth = true;
        $this->SMTPSecure = "tls";
        $this->Port = "587";
        $this->Username = 'emailuser';
        $this->Password = 'emailpass';
    }
}

这显然是在脚本上调用的,并填充了接收者和消息等。

然而,SMTPSecure 方面增加了大约 2 秒 (或有时更多)发送消息所花费的时间。目前,这种延迟发生在单个消息发送上,我希望(我想我在某处读到过)SMTP secure 只需要调用一次即可将 X 条消息发送到 X收件人的数量。


奖金问题:

我想我可以做这样的事情:

$sender = new MailerSMTP();
$sender->subject ="hello";
$sender->Body = "message";
foreach($receiver as $row){
    $sender->addAddress($row['email']);
    $sender->send();
    $sender->clearAddresses();
}

这会在仅延迟 2 秒 SMTPSecure 的情况下发送所有电子邮件吗?

是的,TLS 增加了一些连接开销。您可以通过没有 TLS 的 SMTP 提交到本地邮件服务器来避免它 - 这是释放脚本的最快方法。它保持安全,因为它不会离开服务器,您可以将邮件服务器配置为从那里安全地中继。

您几乎已经了解了多条消息,但我建议您查看 PHPMailer 提供的 mailing list example。一次发多条消息最重要的是开启keepalive,避免每条消息重复连接开销