如何提高发送安全 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收件人的数量。
- 虽然我承认这种延迟可能在某种程度上是不可避免的,但我想就如何通过这种方法提高安全 SMTP 的效率提出一些建议?
奖金问题:
- 无论通过它发送的电子邮件数量如何,当此 class 被实例化时,这种延迟只会发生一次,我的想法是否正确?
我想我可以做这样的事情:
$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,避免每条消息重复连接开销
我在使用 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收件人的数量。
- 虽然我承认这种延迟可能在某种程度上是不可避免的,但我想就如何通过这种方法提高安全 SMTP 的效率提出一些建议?
奖金问题:
- 无论通过它发送的电子邮件数量如何,当此 class 被实例化时,这种延迟只会发生一次,我的想法是否正确?
我想我可以做这样的事情:
$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,避免每条消息重复连接开销