During mail preparation, to provide to all mails an independent context, the context is cloned for each mail. The XWikiContext itself contains reference to the current Hibernate session and Hibernate transaction, and these get cleanup (rollback transaction) in the original context, but are kept closed in the cloned context. When the cloned context is used for an hibernate transaction, the state of the transaction is wrong, causing:
Caused by: org.hibernate.SessionException: Session is closed!
The hibernate session/transaction should be clean up before clone to prevent this issue.