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

Make configured mailers selectable in the back end #1469

Closed
wants to merge 6 commits into from

Conversation

fritzmg
Copy link
Contributor

@fritzmg fritzmg commented Mar 2, 2020

Q A
Fixed issues Fixes contao/core-bundle#1613
Docs PR or issue TODO

This makes the configured Swiftmailer mailers selectable in the back end for website roots, forms and newsletter channels. Example:

swiftmailer:
  mailers:
    contao_newsletter:
      transport: smtp
      username: email@example.org
      password: cuJA6gDKle
      host: smtp.example.org
      port: 587
      encryption: tls
    contao_forms:
      transport: smtp
      username: email@example.com
      password: B3UEd0K44X
      host: smtp.example.com
      port: 587
      encryption: tls

pr1

You can also provide translations:

# translations/mailers.de.yml
default: 'Default'
contao_newsletter: 'Newsletter'
contao_forms: 'Formulare'

pr2

It is also possible to override the From: address for each mailer in the contao config:

contao:
  mailers:
    from_addresses:
      contao_newsletter: Max Foo <foo@example.org>
      contao_forms: arr@example.com

@fritzmg fritzmg changed the title Make configured mailers selectable in the back end [WIP] Make configured mailers selectable in the back end Mar 2, 2020
@fritzmg fritzmg changed the title [WIP] Make configured mailers selectable in the back end Make configured mailers selectable in the back end Mar 2, 2020
@leofeyer leofeyer added this to the 4.10 milestone Mar 3, 2020
leofeyer pushed a commit that referenced this pull request Jul 1, 2020
Description
-----------

This PR replaces the usage of `symfony/swiftmailer-bundle` with `symfony/mailer`. It serves as a basis for a follow-up PR for the available mailer selection based on the [Symfony Mailer Component](https://symfony.com/doc/4.4/mailer.html) (which would replace the existing draft #1469 based on the Swiftmailer Bundle).

The switch is pretty straight forward actually. However there are some things to consider which I will comment on in the files view.

Commits
-------

38ae891 switch to symfony/mailer
f7ac5f4 make port optional
d3243e2 change MAILER_DSN back to MAILER_URL
73a7fd5 dynamically add default mailer
6ddec29 fix code style
d820da6 add \Swift_Mailer fallback
c793448 fix automatic embedding of images
525dfd6 add comment
db5e1ba use MAILER_DSN with MAILER_URL fallback
193821a remove Email deprecation
44536cd allow query options from MAILER_URL
c905ddc increase symfony/mailer dependency
8906865 add comment about why we add default mailer dynamically
399d6b5 add comment about the gmail transport
21983dc add invalid argument exception
5821447 code style fix
3981e8c update dependencies
181a9c3 update dependencies
c8b8f42 update dependencies
aa46267 only allow Symfony 4.4
@leofeyer leofeyer removed this from the 4.10 milestone Jul 16, 2020
leofeyer added a commit that referenced this pull request Jul 17, 2020
Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes contao/core-bundle#1613
| Docs PR or issue | contao/docs#465

_Note:_ this PR depends and is based on #1829. It will be rebased, once #1829 got merged.

This is the alternative version of #1469, based on the [Symfony Mailer Component](https://symfony.com/doc/4.4/mailer.html) instead of the Swiftmailer Bundle. It makes the configured `framework.mailer.transports` selectable in the back end. Example:

```yml
# config/config.yml
framework:
  mailer:
    transports: 
      app: smtps://app@example.org:foobar@example.org:465
      page: smtps://page@example.org:foobar@example.org:465
      forms: smtps://forms@example.org:foobar@example.org:465
      newsletter: smtps://newsletter@example.org:foobar@example.org:465

contao:
  mailer:
    transports:
      page: ~
      forms: ~
      newsletter: ~
```

<img src="https://user-images.githubusercontent.com/4970961/84607561-e3a06d00-aea5-11ea-9f89-daac495b8a85.png" alt="mailer_transport_01" width="576">

_Note:_ only the transports configured in `contao.mailer.transports` will be available for selection.

You can also provide translations:

```yml
# translations/mailer_transports.en.yml
page: 'Page'
forms: 'Forms'
newsletter: 'Newsletters'
```

<img src="https://user-images.githubusercontent.com/4970961/84607577-f7e46a00-aea5-11ea-9cd1-59271843609b.png" alt="mailer_transport_02" width="576">

And you can override the `From` address for each transport in the Contao configuration:

```yml
contao:
  mailer:
    transports:
      page:
        from: Contao Page <page@example.org>
      forms:
        from: Contao Forms <forms@example.org>
      newsletter:
        from: Contao Newsletter <newsletter@example.org>
```

<img src="https://user-images.githubusercontent.com/4970961/84607478-670d8e80-aea5-11ea-9bdd-1cb2b090fd5a.png" alt="mailer_transport_03" width="576">

_Note:_ only the transports configured in `contao.mailer.transports` will be available for selection.

Using the Symfony Mailer Component for this seems more elegant to me, since it requires no change whatsoever in the `\Contao\Email` class ([see the comparison](fritzmg/contao@feature/symfony-mailer...feature/available-symfony-mailers)). With the Symfony Mailer Component, the transport to be used is simply chosen with an `X-Transport` header in the email message itself.

This PR decorates the `mailer` service and automatically sets an `X-Transport` header based on the website root settings - and automatically overrides the `From` address based on the chosen transport.

Commits
-------

fd3da56 switch to symfony/mailer
6c21d67 change MAILER_DSN back to MAILER_URL
eeaea32 dynamically add default mailer
6ad300c add \Swift_Mailer fallback
71a5553 use MAILER_DSN with MAILER_URL fallback
cc34824 remove Email deprecation
8c2480a increase symfony/mailer dependency
3926766 switch to symfony/mailer
3fd2799 dynamically add default mailer
43aa11c provide mailer transport selection and from override
c38e864 add missing model property
8cee6db fix AvailableTransportsTest
08c9b20 fix code style
a8d9b59 fix yml style
ca47801 only show configured mailer transports within Contao
e4f774f change translation domain
1722e81 restore previous version requirement
21b55d2 code style fix
1abfc38 rename mailer_transport DCA field to mailerTransport
af8563c use Annotations for mailerTransport options callback
058da89 implement some early outs
4585e9d add missing model methods
a2da52c fix code style
f802003 Merge remote-tracking branch 'origin/master' into feature/available-symfony-mailers
a5d7c74 add more unit tests
94203d7 use assertSame
38c3de9 improve testAnnotatedCallbacks test
3ca8e02 Rearrange the form fields in the back end
33f38c4 add missing methods
b7159fe change wording to 'mailer transport'
ba4f423 merge with master
b8ffb36 Apply suggestions from code review

Co-authored-by: Leo Feyer <github@contao.org>
@leofeyer
Copy link
Member

@fritzmg Do we still need this PR now that we have added configurable mailer transports in #1830?

@fritzmg
Copy link
Contributor Author

fritzmg commented Oct 17, 2020

No, can be closed :)

@fritzmg fritzmg closed this Oct 17, 2020
AlexejKossmann pushed a commit to AlexejKossmann/contao that referenced this pull request Apr 6, 2021
Description
-----------

This PR replaces the usage of `symfony/swiftmailer-bundle` with `symfony/mailer`. It serves as a basis for a follow-up PR for the available mailer selection based on the [Symfony Mailer Component](https://symfony.com/doc/4.4/mailer.html) (which would replace the existing draft contao#1469 based on the Swiftmailer Bundle).

The switch is pretty straight forward actually. However there are some things to consider which I will comment on in the files view.

Commits
-------

38ae891 switch to symfony/mailer
f7ac5f4 make port optional
d3243e2 change MAILER_DSN back to MAILER_URL
73a7fd5 dynamically add default mailer
6ddec29 fix code style
d820da6 add \Swift_Mailer fallback
c793448 fix automatic embedding of images
525dfd6 add comment
db5e1ba use MAILER_DSN with MAILER_URL fallback
193821a remove Email deprecation
44536cd allow query options from MAILER_URL
c905ddc increase symfony/mailer dependency
8906865 add comment about why we add default mailer dynamically
399d6b5 add comment about the gmail transport
21983dc add invalid argument exception
5821447 code style fix
3981e8c update dependencies
181a9c3 update dependencies
c8b8f42 update dependencies
aa46267 only allow Symfony 4.4
AlexejKossmann pushed a commit to AlexejKossmann/contao that referenced this pull request Apr 6, 2021
…tao#1830)

Description
-----------

| Q                | A
| -----------------| ---
| Fixed issues     | Fixes contao/core-bundle#1613
| Docs PR or issue | contao/docs#465

_Note:_ this PR depends and is based on contao#1829. It will be rebased, once contao#1829 got merged.

This is the alternative version of contao#1469, based on the [Symfony Mailer Component](https://symfony.com/doc/4.4/mailer.html) instead of the Swiftmailer Bundle. It makes the configured `framework.mailer.transports` selectable in the back end. Example:

```yml
# config/config.yml
framework:
  mailer:
    transports:
      app: smtps://app@example.org:foobar@example.org:465
      page: smtps://page@example.org:foobar@example.org:465
      forms: smtps://forms@example.org:foobar@example.org:465
      newsletter: smtps://newsletter@example.org:foobar@example.org:465

contao:
  mailer:
    transports:
      page: ~
      forms: ~
      newsletter: ~
```

<img src="https://user-images.githubusercontent.com/4970961/84607561-e3a06d00-aea5-11ea-9f89-daac495b8a85.png" alt="mailer_transport_01" width="576">

_Note:_ only the transports configured in `contao.mailer.transports` will be available for selection.

You can also provide translations:

```yml
# translations/mailer_transports.en.yml
page: 'Page'
forms: 'Forms'
newsletter: 'Newsletters'
```

<img src="https://user-images.githubusercontent.com/4970961/84607577-f7e46a00-aea5-11ea-9cd1-59271843609b.png" alt="mailer_transport_02" width="576">

And you can override the `From` address for each transport in the Contao configuration:

```yml
contao:
  mailer:
    transports:
      page:
        from: Contao Page <page@example.org>
      forms:
        from: Contao Forms <forms@example.org>
      newsletter:
        from: Contao Newsletter <newsletter@example.org>
```

<img src="https://user-images.githubusercontent.com/4970961/84607478-670d8e80-aea5-11ea-9bdd-1cb2b090fd5a.png" alt="mailer_transport_03" width="576">

_Note:_ only the transports configured in `contao.mailer.transports` will be available for selection.

Using the Symfony Mailer Component for this seems more elegant to me, since it requires no change whatsoever in the `\Contao\Email` class ([see the comparison](fritzmg/contao@feature/symfony-mailer...feature/available-symfony-mailers)). With the Symfony Mailer Component, the transport to be used is simply chosen with an `X-Transport` header in the email message itself.

This PR decorates the `mailer` service and automatically sets an `X-Transport` header based on the website root settings - and automatically overrides the `From` address based on the chosen transport.

Commits
-------

fd3da56 switch to symfony/mailer
6c21d67 change MAILER_DSN back to MAILER_URL
eeaea32 dynamically add default mailer
6ad300c add \Swift_Mailer fallback
71a5553 use MAILER_DSN with MAILER_URL fallback
cc34824 remove Email deprecation
8c2480a increase symfony/mailer dependency
3926766 switch to symfony/mailer
3fd2799 dynamically add default mailer
43aa11c provide mailer transport selection and from override
c38e864 add missing model property
8cee6db fix AvailableTransportsTest
08c9b20 fix code style
a8d9b59 fix yml style
ca47801 only show configured mailer transports within Contao
e4f774f change translation domain
1722e81 restore previous version requirement
21b55d2 code style fix
1abfc38 rename mailer_transport DCA field to mailerTransport
af8563c use Annotations for mailerTransport options callback
058da89 implement some early outs
4585e9d add missing model methods
a2da52c fix code style
f802003 Merge remote-tracking branch 'origin/master' into feature/available-symfony-mailers
a5d7c74 add more unit tests
94203d7 use assertSame
38c3de9 improve testAnnotatedCallbacks test
3ca8e02 Rearrange the form fields in the back end
33f38c4 add missing methods
b7159fe change wording to 'mailer transport'
ba4f423 merge with master
b8ffb36 Apply suggestions from code review

Co-authored-by: Leo Feyer <github@contao.org>
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.

Problem mit sendmail bzw. SMTP
2 participants