i am sending mail with help of spring in which i want multiple email ids in CC, all receives the mail but problem is when they open the email in rackspace(apps.rackspace.com) it shows only one email id in CC but actually there is multiple email ids and when i open same mail in Mozilla Thunderbird it shows all email ids that i have set in CC of mail
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)
My mail sending code is :
here this are the classes which i am using in below code, yes i am initializing this objects that i have not shown here
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;
After some trial and error i got the solution,
Now i am setting Recipient in MimeMessage message like this
Address[] ia = new InternetAddress[toIds.length];
int i = 0;
for (String address : toIds) {
ia[i] = new InternetAddress(address);
i++;
}
message.addRecipients(RecipientType.TO, ia);
instand of setting emailids in MimeMessageHelper helper as
helper.addTo(toAddress);
And it solved my problem and i am able to see all Recipient in rackspace too. :)