Failed to create cache directory error when sending email

I’m new to nextcloud and running in docker using the nextcloud:19 image.
Everything seems to be working fine, except that when I enter all my email details in settings and then try a test email, I get the following error:

A problem occurred while sending the email. Please revise your settings. (Error: Failed to create cache directory /tmp/45b99751a65339c4de99bdeb0ecac734)

I have tried two different email accounts and get the same error when trying to send a test email with both of them.

Thanks for any help