-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
Symfony version(s) affected: 5.0+
Description
When sending mails using the symfony mailer the line endings in the message to the mailserver are missing the carriage return if S/MIME encryption is used on a linux server.
I've prepared four examples of what gets send to the mailserver:
- windows_unencrypted_mail.txt - A plaintext mail generated on a windows system. All line endings are <CR><LF>
- linux_unencrypted_mail.txt - A plaintext mail generated on a linux system. All line endings are <CR><LF>
- windows_encrypted_mail.txt - An encrypted mail generated on a windows system. All line endings are still <CR><LF>
- linux_encrypted_mail.txt - An encrypted mail generated on linux. The line endings in the mail header are still <CR><LF> but in the mail body the <CR> is missing, only the <LF> is present.
Because of the wrong endings sending huge files leads to the following error:
PHP Fatal error: Uncaught Symfony\Component\Mailer\Exception\TransportException: Expected response code "250" but got code "501", with message "501 Syntax error - line too long". in /example/vendor/symfony/mailer/Transport/Smtp/SmtpTransport.php:298
How to reproduce
The Problem will occur always when sending an S/MIME encrypted Mail like this:
$email = (new Email())
->from('sender@example.com')
->to('recipient@example.com')
->subject('Encrypted mail with attachment')
->attachFromPath('./attachments/LoremIpsum.pdf')
->text(fopen('./attachments/content.txt', 'r'))
->html(fopen('./attachments/content.html', 'r'));
$encrypter = new SMimeEncrypter('./cert/smime.cer');
$encryptedEmail = $encrypter->encrypt($email);
The wrong line endings are also present without an attachment but the server error will occure only if the message is long enough to exceed the maximal line length.
Possible Solution
Fix the line endings in S/MIME encrypted messages.
Additional Information
It is working using Swiftmailer on the same systems so I would conclude the error is in the mailer component and not in openssl or any other system.