wodby / docker4drupal

Docker-based Drupal stack
https://wodby.com/docker4drupal
MIT License
1.24k stars 535 forks source link

ssmtp corrupting email attachments when server is under load #542

Open drasgardian opened 1 year ago

drasgardian commented 1 year ago

By default, mail is sent via ssmtp:

PHP_SENDMAIL_PATH: '"/usr/bin/dos2unix -u | /usr/sbin/ssmtp -t -f"'

PROBLEM: If sending large emails (i.e. with attachments), and the server is under load, such as doing bulk emailing, ssmtp can corrupt the files.

When the system is under load, because of the way php's fwrite works, streaming input into the ssmtp has many more chunks, which increases the likelyhood of the input breaking at a point that causes ssmtp to corrupt the file. Unfortunately the behaviour can be quite intermittent.

A workaround I found was to use the sponge command.

PHP_SENDMAIL_PATH: '"/usr/bin/dos2unix -u | sponge | /usr/sbin/ssmtp -t -f"'

Sponge will "soak up" the input before passing to ssmtp in one go.

sponge is available from the moreutils library, which is not installed in the container by default.

csandanov commented 1 year ago

Thank you for reporting this, this does sound plausible, but were you able to consistently reproduce that this actually fixes the issue? We should come up with some simple local test that demonstrates the issue before introducing new changes