how to queue up sending emails to all users on e-commerce(Laravel) - laravel

I can't find any tutorials how to send multyple email using laravel.First, I thing use foreach but its get error in the future(RTO) or 404, can't handle request.
Please any help.
Thanks in advance. . .
how if use
Mail::queue('emails.market',$data,function($mail)use($emails,$subject,$data){
$mail->to($firstEmailAddredd);
$mail->to($restAllEmailAddredd);
$mail->subject($subject);
$mail->from($emails);
});

As always, i'd recommend reading the documentation a few times to get a good grasp of how all of the Laravel components got together. In this case;
Mail: https://laravel.com/docs/7.x/mail#queueing-mail
Queues: https://laravel.com/docs/7.x/queues
For testing email, I would also strongly recommend using a service like MailTrap to begin with.
Testing steps:
Start by testing sending a single email without queuing to ensure your Mailable is correctly configured
Now queue a single email to ensure that your queue is being worked
Now look at sending multiple emails on the queue
Important Note: When sending multiple queued emails over an SMTP service provided by Google or Microsoft, it is more than likely that they have throttle to stop you sending more than "x emails every minute" (For outlook it is 20 emails a minute). You will need to respect these throttles or your emails will refused and not be sent!

Related

How to improve email robustness? [mailgun, laravel]

I planned to improve email robustness using below way. I am using laravel and mailgun. If any bounces email is in the mailgun then i want to send that to someone related to the email(not to that previous receiver and it related with previous sender or someone) so that i plan to use Task scheduler and schedule every hour this process. After that email send successfully i want to remove that email from mailgun.
I actually want to know how to implement get bounces email from mailgun and if send successfully using Task scheduler i want to remove that email from mailgun. if any sample's to achieve this? or any different ideas?
Normally when a bounce happens, providers such as Mailgun will retry a few times depending on the bounce status/type. After failing to send to that email address, Mailgun will put that address into your Bounces list to avoid sending to that address in the future. There's really no point in trying to send emails to an address which doesn't exist, inbox is full, domain expired, etc. So perhaps you should review your bounce list before you consider doing this. Mailgun's dashboard provides the description and date it happened. If you wish to send to a particular address again, you can remove the address from the bounce list. More about bounces here.
You can use mailgun-php or simply use Guzzle to call their API to retrieve your bounces. I'm not sure what you meant my removing email, but hope this helps.
Edit:
You can use their API to get all your bounces, and also the message content (retention depends on your plan or settings) if you need the original content. You could also use their webhooks to get the failed emails, so you don't really need to schedule/cron.
Edit 2:
The bounce list only stores email addresses of previously bounced emails. Also, I just realized that, if you're checking hourly for bounced messages, looks like the suppression/bounce API won't be of much help since you can't know if a message has failed for an address already on the list. This is the only data from bounce list:
{
"address": "alice#example.com",
"code": "550",
"error": "No such mailbox",
"created_at": "Fri, 21 Oct 2011 11:02:55 GMT"
},
So looks like you've to use the events API or webhooks to get the failed messages.
I've used mailgun-php sometime ago, and I found that the it wasn't easy working with Events on that library due to protected properties of the class. So if you have trouble, maybe just use Guzzle or use webhook approach instead.

Does Aweber have a send email API but broadcast does not solve the problem?

I was about to start developing my companies website which is currently in research phase. I was researching with the Aweber API (https://api.aweber.com/) but did not find the API for using a send mail function.
I came across Create Broadcast API here
https://api.aweber.com/#tag/Broadcasts/paths/~1accounts~1{accountId}~1lists~1{listId}~1broadcasts/post
but this requires a list to be used I want to send email to individual contact in the list separately. Any help would be appreciated.
AWeber's API can only send broadcast messages to a list, or a previously created segment of subscribers. You cannot send messages out to a single person solely using the API.
You could use the web UI to create a segment of "email address is ...", then get the segment and send the message to it using the API, but that requires an extra step.

Sending/Receiving multi-recipient SMS - Twilio API

I am writing an app that will facilitate the sending and receiving of SMS messages via a web application. I would like to allow for multiple recipients (not bulk, just a few recipients at most).
I understand that in order to send to multiple recipients, I have to make multiple API calls, and that is fine. The problem I am having is receiving text messages via the Webhook callback. If the SMS was sent to multiple recipients, I cannot see the other recipients in the callback, just myself as the recipient.
Because of this, I have no idea whether this message was intended for just me, or for other recipients as well. This is a problem, because I would like to show threaded conversations similar to Google hangouts, or the SMS applications on all Andorid and iPhones.
I cannot figure out a way to track conversations, if I can't tell if a received message was sent to just me, or a group of recipients. Any suggestions? I do not yes use Twilio on a production server, so if this is not possible to do using Twilio, but is possible using another service, that would be an option for me as well.
Twilio developer evangelist here.
Twilio doesn't fully support group messaging the way that you are used to it when using a phone. That actually relies on MMS under the hood to keep the members of the group chat synced up.
Where you make multiple API calls to send messages to each user, that is manifested as just a single message with no group attached. Thus, any reply to that message comes solely from that person you sent the message to. There is no group at all at this point.
The link that Alex shared in the comments is the closest way you can get group messaging to work. It relies on everyone messaging one Twilio number and the application behind it fanning the messages out to all the recipients. The blog post also comes with some handy subscribe/unsubscribe administration for the group.

How to run in background Laravel 5

Sending email with Laravel takes time before it is successfully sent, or sometimes it even fails. For this reason I would like to store record in database first and running email sending in background to save user's time. After storing the record, I would like to quickly redirect / refresh the page.
How do I use queue in below email sending code?
$message = new Applyonline($post_title, $cand_name);
$message->attachData($pdf->output(), $attach_name);
Mail::to($to_email)->send($message);
Please advise how to achieve this.
You can use Laravel Queues for this use the following link for complete explanation
Queue Thorough Explaination
I suggest looking into queues. Implementing this is quite easy. Just setup a queue for sending the mail and then add the queue to the mail facade. i.e Mail::to()->queue(new MailQueue);
Queues
Queueing mail

How to know mail send or not send in laravel and which recipient is not getting it?

Hi I am using the bellow function, can you please guide me how can I use Mail::failures(); in it
Mail::send('emails.caregiversetprimary', $templateArray, function($message)use($email)
{
$message->to($email, 'username')->subject('my subject');
});
Mail::failures(); < ====== this gives me black array as I have used wrong email
I am using laravel 4.1
tl;dr
You can know which recipients the email has been sent to but no which recipients have received it.
details
You need a better understanding of how mail servers work. From a Laravel point of view, there is no way (or at least not a simple one*) of knowing which recipients got the email. Its a matter of how mail protocol works. You may know which recipients the message has been sent to but no which recipients actually got it.
With Mail::failures() you get a list of recipients to which Laravel tried to send the email but it failed on actually sending it. But again, if it has been sent there is no straightforward way to known if the mail reached their inbox or no.
*If you happend to use Mailgun, Mandrill or any other 3rd party software then you are not dealing with a mail server 'per se' but with an API service. May be you could check the mail service provider documentation to research if they perform any kind of delivery tracking that you can programatically check.

Resources