mailMessage.editingContext().revert();
} catch (Throwable e) {
if (e instanceof NSForwardException)
e = ((NSForwardException)e).originalException();
log.warn("Caught exception when sending mail: " + ERXUtilities.stackTrace(e));
log.warn("Message trying to send: " + mailMessage + " pk: " + mailMessage.primaryKey());
// ENHANCEME: Need to implement a waiting state to retry sending mails.
mailMessage.setState(ERCMailState.EXCEPTION_STATE);
mailMessage.setExceptionReason(e.getMessage());