我正在使用以下代码向多个用户发送邮件。 所有邮件Id都是正确或真实的,一切正常。邮件ID错误时会出现问题。我添加了一个例外,但我希望当只有一个邮件ID错误时,将邮件发送给其他用户。
任何帮助都是适用的。我需要用同一个邮件发送所有用户。
public void sendEmail(
final Map<String, Object> model,
final String mailTemplate,
final List<User> toUsers,
final List<User> ccUsers,
final String attachedFilename,
final File attachedFile
)
{
subject = (String)model.get("subject");
if(subject==null)
subject = Constants.SFTA_DEFAULT_MAIL_SUBJECT;
if ((toUsers == null || toUsers.size() == 0)
&& (ccUsers == null || ccUsers.size() == 0))
return;
MimeMessagePreparator messagePreparator = new MimeMessagePreparator()
{
public void prepare(MimeMessage mimeMessage) throws Exception {
boolean multipartMode = false;
if ((attachedFilename!=null)
&& (attachedFilename.length()>0)
&& (attachedFile!=null) )
multipartMode = true;
MimeMessageHelper message = new MimeMessageHelper(mimeMessage,multipartMode);
message.setFrom(from);
message.setTo(getInternetAddress(toUsers));
if (ccUsers!=null)
{
List<User> ccFinalUsers = new ArrayList<User>();
for(User user:ccUsers)
{
if(user.getIsActive().equals("Y"))
ccFinalUsers.add(user);
if(user.equals(toUsers.get(0)))
ccFinalUsers.remove(user);
}
message.setCc(getInternetAddress(ccFinalUsers));
}
message.setSubject(subject);
message.setSentDate(new Date());
if ( multipartMode )
message.addAttachment(attachedFilename,attachedFile);
String text = VelocityEngineUtils.mergeTemplateIntoString(
velocityEngine, mailTemplate, model );
message.setText(text, true);
}
};
try {
mailSender.send(messagePreparator);
} catch (Exception e) {
e.printStackTrace();
}
}
答案 0 :(得分:0)
设置mail.smtp.sendpartial