在Laravel中发送大量邮件

3

晚安

问题1.-

我需要为每个活动发送超过1000封电子邮件,为此我使用队列(如Laravel的文档所述),但在发送电子邮件时,我必须等待直到所有电子邮件都发送完毕才能返回控制面板视图。

以下是NewsEvents.php控制器中负责发送电子邮件的“存储”函数:

 public function store(Request $request)
{
    $attributes = request()->validate(News::$rules, News::$messages);

    $news = $this->createEntry(News::class, $attributes);

    //queue for sending emails 
     $this->dispatch(new Nevent($news));


    return redirect_to_resource();
}

“Nevent.php”任务的“handle”函数

 public function handle()
{
    //   
     $users=User::where('tipo_user','user')->get();                  
         foreach($users as $user)
         {
             $user->notify(new EventCreated($this->news));
             echo 'enviado correo';
             Informe::create([
                'event_id' => $this->news->id,
                'total' => '1',
                'tipo' => 'invitacion',
                'dst_id' => $user->id,
                'estado' => 'correcto',
            ]);

         }
}

有什么问题吗?

问题2:

如何每分钟发送一封电子邮件? 由于发送所有电子邮件时,我的服务器响应以下消息:

域名mu.edu.fi已超过每小时允许的最大电子邮件数(100/100(100%))。稍后将重新尝试发送。


最好使用计划命令每分钟发送电子邮件。https://laravel.com/docs/5.6/scheduling - Ganesh Ghalame
1个回答

1
如果您使用Redis服务器来管理作业,则Laravel提供了一个简单的API用于限制API的速率。
Redis::throttle('your job id')->allow(10)->every(60)->then(function () {
// Job logic...
}, function () {


return $this->release(10);
});

希望这有所帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接