Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically use the configured sendmail_path #2236

Closed
wants to merge 4 commits into from

Conversation

fritzmg
Copy link
Contributor

@fritzmg fritzmg commented Sep 4, 2020

Q A
Fixed issues Fixes #1261, may be #64, may be even contao/core-bundle#1613
Docs PR or issue -

A long time ago, Swiftmailer dropped support for the PHP mail function for security reasons and thus forcing you to use either sendmail or smtp. However, when using sendmail, Swiftmailer only uses a hard coded command by default, which might not work on all hosting environments. The PHP mail function on the other hand uses the configured sendmail_path of the PHP configuration, which most likely will work in the respective hosting environment. Since then, there were a lot of cases within the community where emails suddenly did not work anymore, and still did not work with sendmail.

Uncaught PHP Exception Swift_TransportException: "Expected response code 220 but got an empty response

Only recently I learned (and began to understand the implications) that this is because some hosting environments require either a specific sendmail path or specific parameters for the command - which would be appropriately defined in the sendmail_path PHP setting.

This PR automatically injects the sendmail_path into the swiftmailer configuration. Therefore emails should work again out of the box, just like it was before when Swiftmailer still supported PHP mail.

Contao 4.10 is (currently) out of luck here, since Symfony Mailer only supports setting the command (see symfony/symfony#37432) and a native transport that uses the sendmail_path (see symfony/symfony#36131) in the upcoming Symfony 5.2 version (see also #2164).

Note: this PR drops support for swiftmailer/swiftmailer-bundle in version 2.x and increases the version requirement to ^3.2.8, since the feature to set the command is only really available since 3.2.8 (see symfony/swiftmailer-bundle#286). But only for the contao/manager-bundle, since automatically using the sendmail_path is only happening there and thus, if you have a regular Symfony application requiring contao/core-bundle you can still choose to use swiftmailer/swiftmailer-bundle in version 2.x. For the same reason we cannot fix this in Contao 4.4, because there swiftmailer/swiftmailer-bundle can only be installed in a maximum version of 3.2.6, due to other version conflicts.

Note: the unit tests for this are a bit lacking as sendmail_path cannot be changed at runtime.

Testing Needed ❗

As a Windows user 🎖️ I don't have access to the native sendmail binary, only to a "fake sendmail" binary for Windows. However, for some reason this binary (which is also not maintained any more by the original author, afaik) is not working any more (though it did work for me in the past). While I was able to test whether the command is set to the correct value, and the command is also executed without prior errors, I was not able to test whether an email is actually sent.

So to be sure someone on a UNIX based system please test this ;)

  1. Make sure that no mailer_* parameters are set in your parameters.yml.
  2. Make sure that no swiftmailer configuration is set in your config.yml.
  3. Make sure that no MAILER_URL environment variable is used.
  4. Make sure that your sendmail_path PHP setting is correct.
  5. Also verify the sendmail_path setting on the command line first.
  6. Test with swiftmailer:email:send --from=foo@example.com --to=foo@example.com --subject=Test --body=Test.

@fritzmg fritzmg added the bug label Sep 4, 2020
@fritzmg fritzmg added this to the 4.9 milestone Sep 4, 2020
@fritzmg fritzmg self-assigned this Sep 4, 2020
@aschempp
Copy link
Member

aschempp commented Sep 4, 2020

Is there a reason this should not be the default configuration in Symfony?

@fritzmg
Copy link
Contributor Author

fritzmg commented Sep 4, 2020

Run $HOME/.composer/vendor/bin/monorepo-tools composer-json --validate --ansi
$HOME/.composer/vendor/bin/monorepo-tools composer-json --validate --ansi
shell: /bin/bash -e {0}

[ERROR] The following files are not up to date: composer.json

##[error]Process completed with exit code 1.

Hmm, I see, currently we don't allow the composer.json requirements to be out of sync. Though I think we may be should allow this, for such cases?

@fritzmg
Copy link
Contributor Author

fritzmg commented Sep 4, 2020

Is there a reason this should not be the default configuration in Symfony?

🤷 now that symfony/mailer exists, there is not much activity anymore in symfony/swiftmailer-bundle. Not sure if making a PR there is worth it? It's pretty easy to do for the Contao Managed Edition.

@fritzmg
Copy link
Contributor Author

fritzmg commented Sep 4, 2020

Is there a reason this should not be the default configuration in Symfony?

🤷 now that symfony/mailer exists, there is not much activity anymore in symfony/swiftmailer-bundle. Not sure if making a PR there is worth it? It's pretty easy to do for the Contao Managed Edition.

Nevertheless: symfony/swiftmailer-bundle#302

@fritzmg
Copy link
Contributor Author

fritzmg commented Sep 28, 2020

symfony/swiftmailer-bundle 3.5.0 has been released, which should make this PR obsolete :)

@fritzmg fritzmg closed this Sep 28, 2020
@fritzmg fritzmg deleted the configure-sendmail-path branch March 17, 2021 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants