My java appication uses Spring JavaMail for send messages.
<bean id="mailMessage" class="org.springframework.mail.SimpleMailMessage"/>
<bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="${email.smtp}" />
<property name="username" value="${email.user}" />
<property name="password" value="${email.password}" />
<property name="port" value="${email.port}" />
<property name="javaMailProperties">
<props>
<prop key="mail.transport.protocol">smtp</prop>
<prop key="mail.smtp.auth">true</prop>
<prop key="mail.debug">true</prop>
<prop key="mail.mime.multipart.allowempty">true</prop>
</props>
</property>
</bean>
Running the code below, the messages are sent correctly to "To address". But, the "CC" and "BCC" are ignored.
MimeMessage message = ((JavaMailSender)mailSender).createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, email.isMultipart(), "UTF-8");
helper.setFrom(new InternetAddress(email.getFrom(), personal, "UTF-8"));
helper.setTo(email.getTo().split(","));
helper.setSubject(email.getSubject());
helper.setText(email.getText(), email.isHtml());
if (email.getCc() != null && email.getCc().isEmpty()) {
helper.setCc(email.getCc().split(","));
}
if (email.getBcc() != null && email.getBcc().isEmpty()) {
helper.setBcc(email.getBcc().split(","));
}
if (!emailHidden) {
((JavaMailSender)mailSender).send(message);
}
Can anyone help me with this problem? Thanks a lot!
No wonder they are ignored: You just made a typo in both lines:
email.getCc().isEmpty()
should be:
!email.getCc().isEmpty()
Same in email.getBcc().isEmpty()
.