Send Mail to multiple Recipients in java

后端 未结 12 748
孤城傲影
孤城傲影 2020-12-02 08:23

I want to send a message to multiple Recipients using following the method :

message.addRecipient(Message.RecipientType.TO, String arg1);

<

12条回答
  •  一个人的身影
    2020-12-02 08:57

    InternetAddress.Parse is going to be your friend! See the worked example below:

    String to = "med@joe.com, maz@frank.com, jezz@jam.com";
    String toCommaAndSpaces = "med@joe.com maz@frank.com, jezz@jam.com";
    
    1. Parse a comma-separated list of email addresses. Be strict. Require comma separated list.
    2. If strict is true, many (but not all) of the RFC822 syntax rules for emails are enforced.

      msg.setRecipients(Message.RecipientType.CC,
      InternetAddress.parse(to, true));
      
    3. Parse comma/space-separated list. Cut some slack. We allow spaces seperated list as well, plus invalid email formats.

      msg.setRecipients(Message.RecipientType.BCC,
      InternetAddress.parse(toCommaAndSpaces, false));
      

提交回复
热议问题