This issue has been created
 
 
XWiki Platform / cid:jira-generated-image-avatar-48fb10aa-26a8-465a-b604-03ddc3b29788 XWIKI-25742 Open

Mails sent with a listener other than the database one are never removed from the mail content store

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-c52b48de-4486-42a2-add1-844e333d83dc Thomas Mortagne created this issue on 12/Nov/26 14:14
 
Summary: Mails sent with a listener other than the database one are never removed from the mail content store
Issue Type: cid:jira-generated-image-avatar-48fb10aa-26a8-465a-b604-03ddc3b29788 Bug
Affects Versions: 17.10.15
Assignee: Unassigned
Components: Mail
Created: 12/Nov/26 14:14
Priority: cid:jira-generated-image-static-major-c1b3a8ab-69aa-4845-b1ea-ee0b03f0a063 Major
Reporter: Thomas Mortagne
Description:

Every mail sent through the Mail Sender API is first serialized to <permanent directory>/mails/<batch id>/<message id> (see PrepareMailRunnable). The only code removing that file after a successful send is DatabaseMailListener#onSendMessageSuccess, so any mail sent with another MailListener leaves its file behind forever.

This is what happens with the most common script API: $services.mail.sender.send($message) and send($messages) use the memory listener. Since there is no matching entry in the mailsender_events table, these files don't appear in the Mail Sending Status administration either, so the only way to notice is to look at the permanent directory (which keeps growing, attachments included).

Steps to reproduce

  1. Configure a working SMTP server
  2. Send a mail from a wiki page with Programming right:
    {{velocity}}
    #set ($message = $services.mail.sender.createMessage('from@example.org', 'to@example.org', 'test'))
    #set ($discard = $message.addPart('text/plain', 'test'))
    #set ($result = $services.mail.sender.send($message))
    $result.statusResult.isProcessed()
    {{/velocity}}
    
  3. Look at <permanent directory>/mails/

Expected

The mail being successfully sent, nothing remains in <permanent directory>/mails/.

Actual

A <batch id>/<message id> file containing the full serialized mail remains, and it's not listed in the Mail Sending Status administration. The same happens for a failed send with such listener, while nothing can resend it (there is no status to resend from).

Real case: the Invoices application left one file per invoice mail sent (with the PDF attached) during years.