Search code examples
javamultithreadingemailjakarta-mail

Javamail multiple recepints with multi-threading


I have to send an email to several recipients. I don't want the header to display the complete list of recipients(i.e. I am not using "Message.RecipientType.CC"). If I use "Message.RecipientType.BCC", there is a probability of the mail being sent to spam. So I am using Message.RecipientType.TO to send an email one at a time. The problem is that this can take a very long time. My question is whether a separate thread can be created for every email to be sent in order to improve performance.


Solution

  • You can create a separate thread for each message, which will require a separate connection to the mail server. Depending on your mail server, it may limit the number of connections you can use.

    You can also send the messages serially, using a single connection. Again, depending on your mail server, it may limit the number of messages you can send in a single connection.