Laravel Mail:如何根据特定域发送批量电子邮件

I am building a newsletter management system using Laravel 5.2.45 which allows the ability for users to send mass emails to mailing lists. As of the moment my example mailing list contains thousands of different email addresses with different email providers such as '@gmail.com', '@hotmail.co.uk'... etc.

When the system is in use, newsletters could potentially be sent to 1000's upon 1000's of different emails, which brings me to ask these few questions.

1) Based on research I believe that it is ideal to minimize the number of connections Laravel opens and closes when sending emails. Meaning, to order the provider domains and send them in batches, so sending all '@gmail.com' in one go so only one connection is open and closed to the gmail server. Is this accurate?

2) If question one is accurate, what would be the best route of doing this using Laravel mail (if the native Laravel mail has the capability of doing so)? I am aware of the ability to use Laravel mail's queue functionality but I am unsure if this would make sure only one connection was open and closed per domain type.

3) Additionally, is the any negative impact of using the Laravel mail class to send newsletters that could potentially go to 20,000 customer emails several times a day?

Thank You,

Kieren.

Well, depending on how you have configured your mail adaptor – yes, Laravel would open a connection for each e-mail being sent, which is not very efficient if you plan to send that many e-mails.

I would strongly recommend looking into e-mail providers API:s instead of using a SMTP-connection, most of these offer a batch-functionality. For instance Mailgun: https://documentation.mailgun.com/user_manual.html#batch-sending. Laravel supports the Mailgun-API out of the box.

Your questions:

1) Doesn't matter if you batch the emails after the domain like @gmail.com, @yahoo.com or not, if you have a single to-field that's filled out in a for-loop for example, a new connection would be established for each mail over SMTP. The connection is connected to the sending domain, not the receiving one.

2) I would definitely look into using queues, even if you use Mailguns batch-sending functionality – much more efficient.

3) Negative impact on what way? Of course, depending on how you build the mail templates, set the e-mail data and what not – it could potentially put a strain on the server. But nothing that can't be built around with some proper programming.