Laravel Mail Facade使用本地SMTP发送电子邮件的速度非常慢 [英] Laravel Mail Facade very slow sending email with local SMTP

查看:46
本文介绍了Laravel Mail Facade使用本地SMTP发送电子邮件的速度非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Laravel的Mail门面发送电子邮件.5.3.我正在使用公司的本地SMTP服务器.它非常缓慢,比每秒发送一封电子邮件还要大.无论如何要加快速度?我在Google周围搜寻了一种建立连接,使其保持打开状态并重用它的方法,但是没有骰子.我已经触发了异步,所以排队不会有什么大的帮助,它只会进一步降低速度.

I'm trying to send emails with Laravel's Mail facade. 5.3. I'm using my company's local SMTP server. It's painfully slow, greater than an email per second. Anyway to speed this up? I've googled around for a way to make the connection, hold it open, and reuse it, but no dice. I'm already triggering this async, so queueing wouldn't be a big help, it just push the slowness further down.

foreach($customers as $customer) {

    //build $params, $sendTo, $subject

    Mail::send(array('myemailview',null), $params,
        function($message) use ($sendTo, $subject)
        {
            $message
            ->to([$sendTo])
            ->subject( $subject );

        });
}

推荐答案

即使使用性能最佳的邮件服务器,同步发送电子邮件也会导致延迟.最重要的是,您正在循环运行它.

Even with the best performing mail server, sending an email synchronously will cause delays. To top it off you're running it in a loop.

第一件事是将邮件排队.默认的 sync 队列不执行任何操作,它只是正常运行作业直到完成.您需要设置一个专用队列,例如数据库或Redis.然后将您的邮件发送到队列.与您说排队会使情况变得更糟相反,仅此一项就可以立即消除所有的缓慢情况.

First thing would be to queue the mails. The sync queue which is the default doesn't do anything, it just runs the job normally till it finishes. You need to set up a dedicated queue like database or redis. Then push your mails to the queue. This alone will immediately remove all the slowness contrary to you saying queueing makes it worse.

第二,如果您的邮件具有相同的布局和内容,请考虑使用密件抄送向所有用户发送一封邮件.

Secondly if your mail has the same layout and content then consider sending a single mail to all the users using bcc.

这篇关于Laravel Mail Facade使用本地SMTP发送电子邮件的速度非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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