遵循我使用 Spring 3 TaskExecutor 为异步邮件发送所做的代码。代码工作正常,我只想知道是否有任何邮件因任何原因未能发送,然后必须再次将其添加到队列中并且必须重试发送。
我已经用 Google 搜索过,但没有获得有关重试政策的信息。
帮助将不胜感激!
@Service
public class AsyncMailSender implements MailSender {
/* Logger for Search-Controller Class */
public static final Logger LOGGER = Logger.getLogger(AsyncMailSender.class);
@Autowired
private MailSender mailSender;
@Autowired
private TaskExecutor taskExecutor;
@Autowired
private VelocityEngine velocityEngine;
public void send(SimpleMailMessage simpleMessage) throws MailException {
Map<String, Object> modelMap = new HashMap<String, Object>();
modelMap.put("user", "Manoj");
simpleMessage.setText(VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "templates/email.vm", modelMap));
taskExecutor.execute(new AsyncMailTask(simpleMessage));
}
public void send(SimpleMailMessage[] simpleMessages) throws MailException {
for (SimpleMailMessage message : simpleMessages) {
send(message);
}
}
private class AsyncMailTask implements Runnable {
private SimpleMailMessage message;
private AsyncMailTask(SimpleMailMessage message) {
this.message = message;
}
public void run() {
LOGGER.info("Sending Emails" + message.getSubject());
mailSender.send(message);
}
}
}