How to send an email to multiple recipients in Spring

前端 未结 8 2226
花落未央
花落未央 2021-02-12 10:48

The email gets sents only to the last email address in the String[] to array. I\'m intending to send to all email addresses added to the array. How can I make that

8条回答
  •  悲&欢浪女
    2021-02-12 11:14

    It's working well with the SimpleMailMessage. like the answer of Siri

    String[] to = {"user1@gmail.com", "user2@gmail.com"};
            
    SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
    simpleMailMessage.setTo(to);
    simpleMailMessage.setSubject("subject of mail");
    simpleMailMessage.setText("content of mail");
    
    try {
        javaMailSender.send(simpleMailMessage);
    } catch (MailSendException e) {
         //...
    }   
    

提交回复
热议问题