通过 MimeMessageHelper 发送邮件将邮件发送到所有 CC,但在机架空间中,它仅在 CC 中显示一个电子邮件 ID

Send Mail by MimeMessageHelper sends mail to All CC but in rackspace it shows only one email id in CC

我在 spring 的帮助下发送邮件,其中我想要 CC 中的多个电子邮件 ID,所有人都收到了邮件,但问题是当他们在 rackspace 中打开电子邮件时(apps.rackspace.com) 它在 CC 中只显示一个电子邮件 ID,但实际上有多个电子邮件 ID,当我在 Mozilla Thunderbird 中打开相同的邮件时,它显示了我在 CC of mail

中设置的所有电子邮件 ID

cc in rackspace is shown as CC:test@mydomain.com (here 3 email ids in cc,but rackspace shows only one)

cc in Mozilla Thunderbird is shown as CC:test@mydomain.com,test2@mydomain.com,test3@mydomain.com (here all 3 email ids in cc is displaying)

我的邮件发送代码是:

这是我在下面的代码中使用的 类,是的,我正在初始化这里没有显示的对象

JavaMailSender mailConfig;
MimeMessageHelper helper;
MimeMessage message;
String[] to;    
String[] cc;


try {

    message.setContent(msg, "text/html; charset=utf-8");
    message.setHeader("Content-Type", "text/html; charset=utf-8");

    if (toEmailIds == null) {
        helper.setTo(to);
    } else {
        String[] toIds = toEmailIds.split(",");

        for(String toAddress : toIds){
            helper.addTo(toAddress);
        }

    //  helper.setTo(toIds); tried this too but it doesnot make any change
    }

    if (ccEmailIds != null) {

        for(String ccAddress : ccEmailIds){
            helper.addCc (ccAddress);
        }

    //  helper.setCc(ccEmailIds);
    }

    if (subject == null) {
        helper.setSubject(defaultSubject);
    } else {
        helper.setSubject(subject);
    }

    SendMailByThread sendmailthread = new SendMailByThread(mailConfig, message);
    new Thread(sendmailthread).start();
} catch (Exception e) {
    isSentSuccessfully = false;
    StringBuilder sb = new StringBuilder("cannot send mail to : ");
    sb.append(Arrays.toString(to));
    sb.append(" \nerror message is : ");
    sb.append(e.getMessage());
    sb.append(" \nemail content is : \n");
    sb.append(msg);
    log.error(sb.toString(), e);
    sb = null;
}
return isSentSuccessfully;

经过反复试验,我得到了解决方案,

现在我在 MimeMessage 消息中设置收件人 像这样

            Address[] ia = new InternetAddress[toIds.length];
            int i = 0;
            for (String address : toIds) {
                ia[i] = new InternetAddress(address);
                i++;
            }

            message.addRecipients(RecipientType.TO, ia);

将 MimeMessageHelper 助手中的电子邮件 ID 设置为

helper.addTo(toAddress);

它解决了我的问题,我也能够在机架空间中看到所有收件人。 :)