如何提高发送安全SMTP电子邮件的速度? [英] How can I increase the speed of sending Secure SMTP emails?

查看:426
本文介绍了如何提高发送安全SMTP电子邮件的速度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Exim 4.87的服务器上安装了PHPMailer 5.2.16,该服务器还具有用于安全连接的TLS证书.

I have a PHPMailer 5.2.16 on a server using Exim 4.87 which also has a TLS certificate for secured connections.

我的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';
    }
}

这显然是在脚本上调用的,并填充有收件人和消息等.

And this is obviously called on the script and populated with reciever and message, etc.

然而,SMTPSecure方面增加了发送消息所花费的时间约 2秒(有时甚至更多).目前,这种延迟是在发送单个邮件时发生的,我会<希望> (我想我读过某处),只需将SMTP安全调用一次,即可将X数量的邮件发送给X数量的收件人.

However the SMTPSecure aspect adds about 2 seconds (or sometimes a bit more) on to the time taken to send the message. Currently this delay is on a single message sending, and I would hope (I think I read somewhere) that the SMTP secure would only need to be called once to send X number of messages to X number of recipients.

  • 尽管我在某种程度上不可避免地接受了可能的延迟,但我想对如何通过这种方法提高安全SMTP的效率提出一些建议?
  • While I accept this delay might be unavoidable to some extent, I would like some advice on to how to improve the efficiency of secured SMTP via this method?

奖金问题:

  • 我是否正确地认为这种延迟将在实例化此类时仅发生一次,而不管通过它发送的电子邮件数量如何?

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

I would imagine I can do something like this:

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

这是否仅延迟2秒发送所有电子邮件?

Would this send all emails with only a 2 second SMTPSecure delay?

推荐答案

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

Yes, TLS adds some connection overhead. You can avoid it by submitting to a local mail server over SMTP without TLS - that's the fastest way to free up your script. It remains secure because it's not leaving the server, and you can configure your mail server to relay securely from there onwards.

关于多条消息,您已经快到了,但是我建议您查看

You're nearly there on the multiple messages thing, but I recommend looking at the mailing list example provided with PHPMailer. The most important thing when sending multiple messages in one go is to enable keepalive, which avoids repeating the connection overhead for each message.

这篇关于如何提高发送安全SMTP电子邮件的速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆