向 5000 封电子邮件发送警报

问题描述 投票:0回答:1

我想用 Laravel 向 5000 发送警报,警报发送到前 50 个并停止,它给我这个错误“预期响应代码“250”但代码“450”,并显示消息“450 4.7.1 错误:来自 197.230.172.76 的邮件太多”。'

这是我的代码 公共函数句柄(JobAlertEvent $event) {

    $jobLocations = $event->job->jobLocation->pluck('id')->toArray();

    $location_event=JobLocation::select('location')->where('id', '=', $jobLocations[0])->get()[0]->location;
    $category_event=$event->job->category;

    $jobAlerts = JobAlert::select('job_alerts.*','job_categories.name as categories','job_locations.location as locations')
                            ->join('job_alert_categories', 'job_alerts.id', '=', 'job_alert_categories.job_alert_id')
                            ->join('job_categories', 'job_alert_categories.category_id', '=', 'job_categories.id')
                            ->join('job_alert_locations', 'job_alerts.id', '=', 'job_alert_locations.job_alert_id')
                            ->join('job_locations', 'job_alert_locations.location_id', '=', 'job_locations.id')
                            ->where('job_alerts.status', '=', 'active')
                            ->where('job_locations.location', '=', $location_event)
                            ->where('job_categories.name', '=', $category_event)
                            ->get();
    
    $l=JobJobLocation::orderBy('id', 'desc')->pluck('id')->toArray();
   
    $chunks = array_chunk($jobAlerts->toArray(), 1000);
    foreach ($chunks as $chunk) {
        // Convertir les tableaux associatifs en modèles Eloquent
        $jobAlertModels = collect($chunk)->map(function ($item) {
            return new JobAlert($item);
        });

        // Vérifier l'adresse e-mail et envoyer les alertes
        foreach ($jobAlertModels as $jobAlert) {
      

            Notification::send($jobAlert, new NotificationsJobAlert($event->job, max($l)));
        }
    }
    
laravel smtp sendmail alerts email-spam
1个回答
0
投票

在短时间内发送大量电子邮件时经常会遇到此错误。要解决此问题并在不达到速率限制的情况下发送大量电子邮件,您可以考虑以下方法

使用事务性电子邮件服务:考虑使用事务性电子邮件服务,例如 SendGrid、Mailgun 或 Amazon SES(简单电子邮件服务)。这些服务专为发送大量电子邮件而设计,通常提供 API 和 SMTP 集成选项,使您能够高效管理和发送电子邮件。

发送速率限制:对您的电子邮件发送过程实施速率限制,以确保您不会超出电子邮件服务器或收件人服务器施加的限制。您可以限制电子邮件的发送速率以保持在允许的限制内。

批量处理:将 5000 个收件人的列表分成较小的批次,并分别向每个批次发送电子邮件。这有助于分配负载并防止达到速率限制。

配置 SMTP 中继: 如果您使用自己的电子邮件服务器,请确保其配置正确。您可能需要配置 SMTP 中继以有效处理传出电子邮件流量并防止速率限制问题。

验证您的电子邮件列表:确保您的电子邮件列表干净且最新。向无效或不存在的地址发送电子邮件可能会触发速率限制或导致您的电子邮件被标记为垃圾邮件。

联系您的电子邮件服务提供商:如果您使用第三方电子邮件服务,请联系他们的支持人员寻求帮助。他们也许能够帮助您解决速率限制问题或提供有关优化电子邮件发送流程的指导。

© www.soinside.com 2019 - 2024. All rights reserved.