O
O
Orkhan Hasanli2018-11-24 02:51:45
Java
Orkhan Hasanli, 2018-11-24 02:51:45

How to send emails to multiple users in Spring?

Hello!
How to send emails to multiple users? When creating an article, you need to send messages to different users. Now, according to my code, the message only comes to the last user...
Here is the code:

public void sendMails (String[] to, String subject, String body) throws MessagingException {

        MimeMessage message = javaMailSender.createMimeMessage();

        MimeMessageHelper helper = new MimeMessageHelper( message, true );

        helper.setFrom(from);

        helper.setTo(to);

        helper.setSubject(subject);
        helper.setText(body);

        javaMailSender.send(message);
    }

Only the last user receives the message (
The following resources I found did not help much:
https://stackoverflow.com/questions/26867055/how-t...
https://stackoverflow.com/questions/13854037/send-...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Cheremisin, 2018-11-24
@azerphoenix

The correct tone would be to send a separate email to each user . Firstly, no one will know the number of subscribers, and secondly, the letter must be personalized.
Well, at least try using apache commons email - https://commons.apache.org/proper/commons-email/in...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question