I want to send newsletters to multiple users, but when I try my code, the emails can be seen by everyone. And if I send it using looping, I'm afraid it will take a long time because there are many users. Is there a good solution to send multiple emails?
This is my code (I use SMTP):
await Mail.send('newsletter', data, (message) => {
message
.from('newsletter@web.com', 'Admin')
.subject('New Events Notification')
.to(emails) // array consist of multiple emails
})
You can use the sendLater
method to send multiple emails. The Adonis js uses the memory queue inside this method. So it will not block your HTTP request.
After replacing the method your code will look like this .
await Mail.sendLater('newsletter', data, (message) => {
message
.from('newsletter@web.com', 'Admin')
.subject('New Events Notification')
.to(emails) // array consist of multiple emails
})
Now you can add your loop and Adonis js will send email in background.