docker4drupal icon indicating copy to clipboard operation
docker4drupal copied to clipboard

ssmtp corrupting email attachments when server is under load

Open drasgardian opened this issue 2 years ago • 1 comments

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.

drasgardian avatar Feb 16 '23 08:02 drasgardian

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

csandanov avatar Feb 16 '23 10:02 csandanov