Skip to content

Add Mailer send and debug commands #43687

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

Closed
wants to merge 1 commit into from
Closed

Conversation

fritzmg
Copy link
Contributor

@fritzmg fritzmg commented Oct 24, 2021

Q A
Branch? 5.4
Bug fix? no
New feature? yes
Deprecations? no
Tickets -
License MIT
Doc PR TBD

The old and deprecated Swiftmailer Bundle had a few useful features that are still absent with the current Symfony Mailer implementation: for instance being able to quickly test your email configuration by sending a test email via the command line.

This PR provides a mailer:send and mailer:debug command. The implementation is more or less copied over from the Swiftmailer Bundle.

mailer:send interactively asks you for the sender address, recipient address, subject and message body and then sends the email via the default mailer transport. Additionally you can set the chosen transport via --transport for example, if you use multiple mailer transports.

mailer:debug shows you name and DSN of all your configured mailer transports (or just name and DSN of a specified transport).

Discussion

Currently there is no way to retrieve the available mailer transports from the container. By contrast the Swiftmailer Bundle registers each individual transport in the container as a service, which can then be retrieved in the commands. In the current Mailer implementation they are only passed to mailer.transports and cannot be retrieved otherwise (or at least I could not figure out how). This PR implements a getTransports method for the Transports class, however I suppose it should be done differently (new interface?).

@carsonbot carsonbot added this to the 5.4 milestone Oct 24, 2021
@fritzmg fritzmg changed the title Add Mailer send and debug commands [Mailer] Add Mailer send and debug commands Oct 24, 2021
@fritzmg
Copy link
Contributor Author

fritzmg commented Oct 25, 2021

for the send, maybe #39173 and #37409 are still relevant

Oh I see, didn't find the existing issues/PRs before.

NewEmailCommand: I don't see the use cases and as such, I don't want it in core

@fabpot I agree with the comments in previous PRs, i.e. that it is a helpful tool to test sending of emails in your application - and we have used it as such in numerous projects with Swiftmailer Bundle. Since we switched from Swiftmailer to Symfony Mailer in Contao 4.10 and up however, this feature is sorely missed by us and other members of the Contao community. If the decision is (again) made to not include this, we can of course instead provide a command within Contao.

@fabpot fabpot modified the milestones: 5.4, 6.1 Oct 29, 2021
@fritzmg fritzmg force-pushed the mailer-command branch 2 times, most recently from 31adda6 to 9982509 Compare December 26, 2021 18:44
@fabpot fabpot modified the milestones: 6.1, 6.2 May 20, 2022
@vinceAmstoutz
Copy link

@fabpot Why 6.2 and not 6.1 ? Thanks you for advance.

@FabienPapet
Copy link

@vinceAmstoutz 6.1 is in feature freeze, so only bug fixes will be fixed until 6.1 is out (end of this month)

@fritzmg
Copy link
Contributor Author

fritzmg commented May 23, 2022

@FabienPapet I think the question is why this has been moved from 5.4 to 6.1 and then from 6.1 to 6.2, i.e. is there still any intention of merging this? There was no feedback to my last comment and thus I haven't followed up here and did not fix the conflict yet.

@vinceAmstoutz
Copy link

@FabienPapet I think the question is why this has been moved from 5.4 to 6.1 and then from 6.1 to 6.2, i.e. is there still any intention of merging this? There was no feedback to my last comment and thus I haven't followed up here and did not fix the conflict yet.

Exactly, thx !

@vinceAmstoutz
Copy link

@vinceAmstoutz 6.1 is in feature freeze, so only bug fixes will be fixed until 6.1 is out (end of this month)

See @fritzmg response. Thx for advance

@FabienPapet
Copy link

I think this is a miss for this PR to not be reviewed, but I guess as this PR has not been updated, It has been forgotten, and now moved to 6.2.

I'd also really liked to see this feature in 6.1 as i always create a mail:send command in all my projects but I saw this PR only today :/

@fritzmg
Copy link
Contributor Author

fritzmg commented May 23, 2022

This feature has been rejected for almost two years now - I did not want to put in any additional effort before confirming that it will now finally make it in.

@FabienPapet
Copy link

FabienPapet commented May 23, 2022

I understand that, I think we need to (re)consider that again after 2 years ? Maybe open a RFC for this ?

@wouterj wouterj removed their request for review May 23, 2022 10:34
@fritzmg
Copy link
Contributor Author

fritzmg commented Jun 20, 2022

Maybe open a RFC for this ?

Open where? I just need a confirmation from @fabpot (or whoever) here that Symfony is interested in merging this and then I can continue working on this PR.

@fritzmg
Copy link
Contributor Author

fritzmg commented Jun 20, 2022

In any case you can now install inspiredminds/symfony-mailer-command-bundle for the basic mailer:send command.

@vinceAmstoutz
Copy link

It's still sad to come to this! I regret (although I love the Framework ;) ) the management of this @fabpot @FabienPapet ticket. It's not nice to leave people in the dark and in doubt for so long ...

Sincerely.

@FabienPapet
Copy link

ping @nicolas-grekas @chalasr , It looks like no one from the core team has been giving it's opinion on this. Any help ? :)

->addOption('transport', null, InputOption::VALUE_OPTIONAL, 'The transport to be used')
->addOption('content-type', null, InputOption::VALUE_REQUIRED, 'The body content type of the message', 'text/plain')
->addOption('charset', null, InputOption::VALUE_REQUIRED, 'The body charset of the message', 'utf-8')
->addOption('body-source', null, InputOption::VALUE_REQUIRED, 'The source of the body [stdin|file]', 'stdin')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would only support stdin as it also allows to get content from a file.

@carsonbot carsonbot changed the title [Mailer] Add Mailer send and debug commands Add Mailer send and debug commands Jun 22, 2022
@fritzmg
Copy link
Contributor Author

fritzmg commented Jun 23, 2022

General question: I originally put the command(s) in Symfony\Component\Mailer\Command, however now I realise they should probably live in Symfony\Bundle\FrameworkBundle\Command, correct?

@fabpot fabpot force-pushed the mailer-command branch 5 times, most recently from 7a0a90a to 2931282 Compare July 23, 2022 14:22
@fabpot
Copy link
Member

fabpot commented Jul 23, 2022

Closing in favor of #47040 which implements a command that eases testing sending an email instead of trying to have a semi-generic command to send emails. It should be enough to cover the use cases mentioned here, and as a bonus, it bypasses the message bus to ease testing.

@fabpot fabpot closed this Jul 23, 2022
fabpot added a commit that referenced this pull request Jul 24, 2022
This PR was merged into the 6.2 branch.

Discussion
----------

Add a mailer:test command

| Q             | A
| ------------- | ---
| Branch?       | 6.2
| Bug fix?      | no
| New feature?  | yes <!-- please update src/**/CHANGELOG.md files -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tickets       | Fix #43687, Fix #39173, Fix #37409
| License       | MIT
| Doc PR        |

This PR introduces a `mailer:test` command that helps test if sending emails works correctly.
The only argument is the `To` header. Everything is optional.
There is no support for complex emails (STDIN for body, HTML support, attachments, ...) as the goal is to test if a transport works correctly.

Note that this command bypasses the Messenger bus if configured to ease testing even when the messenger consumer is not running.

Commits
-------

dee0d09 Add a mailer:test command
@fritzmg fritzmg deleted the mailer-command branch August 30, 2023 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants