我的Java应用程序使用Spring JavaMail发送消息。
<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>
运行下面的代码,消息将正确发送到“收件人”。但是,“ CC”和“ BCC”被忽略。
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);
}
谁能帮我解决这个问题?非常感谢!
最佳答案
难怪它们会被忽略:您只是在两行中输入了错字:
email.getCc().isEmpty()
应该:
!email.getCc().isEmpty()
在
email.getBcc().isEmpty()
中相同。关于java - JavaMail-抄送和密件抄送地址被忽略,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48547596/