I want to send an alert to 5000 with Laravel, the alert sends to the first 50 and stops and it gives me this error.
"Expected response code "250" but code "450", with the message "450 4.7.1 Error : too much mail from 197.230.172.76".'
$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)));
}
}
This error is often encountered when sending a large volume of emails in a short period of time.To address this issue and send a large number of emails without hitting rate limits, you can consider the following approaches
Use a Transactional Email Service: Consider using a transactional email service like SendGrid, Mailgun, or Amazon SES (Simple Email Service). These services are designed for sending large volumes of email and often provide APIs and SMTP integration options that allow you to manage and send emails efficiently.
Rate Limit Sending: Implement rate limiting on your email sending process to ensure you don't exceed the limits imposed by your email server or the recipient's server. You can throttle the rate at which emails are sent to stay within the allowed limits.
Batch Processing: Divide your list of 5000 recipients into smaller batches and send emails to each batch separately. This helps distribute the load and prevents hitting rate limits.
Configure SMTP Relays: If you're using your own email server, ensure it's properly configured. You may need to configure SMTP relays to handle outgoing email traffic efficiently and prevent rate-limiting issues.
Verify Your Email List: Ensure that your email list is clean and up-to-date. Sending emails to invalid or non-existent addresses can trigger rate-limiting or result in your emails being marked as spam.
Contact Your Email Service Provider: If you're using a third-party email service, contact their support for assistance. They may be able to help you resolve rate-limiting issues or provide guidance on optimizing your email sending process.