Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Mailer] [DX] Introduce send email command #39173

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

Conversation

gmorel
Copy link

@gmorel gmorel commented Nov 25, 2020

Q A
Branch? 5.x for features
Bug fix? no
New feature? yes
Deprecations? no
Tickets -
License MIT
Doc PR symfony/symfony-docs#...

Pain Point

Sometimes in production you might have a doubt whether your mailer is well configured or if your mail supplier is still up and running.

Aim is to allow to quickly check if your mailer configuration or supplier is operational in (production or elsewhere).

This is the same (lighter) feature we had in SwiftMailerBundle.

Usage

TODO

Keep up the good work 🚀

@carsonbot
Copy link

Hey!

I like what you have done here. Keep up the good work.

To help keep things organized, we don't allow "Draft" pull requests. Could you please click the "ready for review" button or close this PR and open a new one when you are done?

Note that a pull request does not have to be "perfect" or "ready for merge" when you first open it. We just want it to be ready for a first review.

Cheers!

Carsonbot

@gmorel gmorel force-pushed the feature/5.x_mailer_debug_command branch from e34cca3 to 6676087 Compare November 25, 2020 16:01
@gmorel gmorel marked this pull request as ready for review November 25, 2020 16:03
@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

  • Always add tests
  • Keep backward compatibility (see https://symfony.com/bc).
  • Bug fixes must be submitted against the lowest maintained branch where they apply (see https://symfony.com/releases)
  • Features and deprecations must be submitted against the 5.x branch.

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

@gmorel gmorel force-pushed the feature/5.x_mailer_debug_command branch from 6676087 to fa19a00 Compare November 25, 2020 16:15
@gmorel gmorel force-pushed the feature/5.x_mailer_debug_command branch 5 times, most recently from 0718900 to be4adbc Compare November 25, 2020 16:37
@gmorel gmorel force-pushed the feature/5.x_mailer_debug_command branch 3 times, most recently from d3d3f5d to e5a6c8e Compare November 25, 2020 18:03
@gmorel gmorel force-pushed the feature/5.x_mailer_debug_command branch from e5a6c8e to d64c4da Compare November 26, 2020 08:56
@jderusse jderusse added this to the 5.x milestone Dec 4, 2020
}

/**
* {@inheritdoc}
Copy link
Contributor

Choose a reason for hiding this comment

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

@stof do we really need all the inheritdoc?

Copy link
Author

Choose a reason for hiding this comment

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

Its up to you. I can remove them.

But my 2cents:
Indeed if you look at the code in an IDE you will have the fancy icon
Screenshot from 2020-12-20 15-14-40
However when you review a code in github having this comment ease the understanding. And especially it highlights the constraints linked to this inheritance.

@gmorel gmorel force-pushed the feature/5.x_mailer_debug_command branch 2 times, most recently from 660c670 to 4a139f6 Compare December 9, 2020 15:02
@gmorel gmorel force-pushed the feature/5.x_mailer_debug_command branch from 4a139f6 to fe1a6b2 Compare December 20, 2020 14:11
/**
* {@inheritdoc}
*/
public function __construct(?MailerInterface $mailer)
Copy link
Author

Choose a reason for hiding this comment

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

todo: check if I can remove the nullable without breaking everything

@OskarStark
Copy link
Contributor

Can you please rename your PR title:

- [Mailer] introduce debug command - DX
+ [Mailer] [DX] Introduce debug command

Thanks

@gmorel gmorel force-pushed the feature/5.x_mailer_debug_command branch from fe1a6b2 to 2cc5306 Compare December 20, 2020 14:34
@gmorel
Copy link
Author

gmorel commented Dec 20, 2020

php composer.phar remove symfony/mailer
php composer phar remove symfony_mailer

php link /home/gmorel/dev/opensource/symfony_full_5.2
in order to simulate php composer.phar require symfony/mailer
php link symfony_full_5 2

@gmorel gmorel changed the title [Mailer] introduce debug command - DX [Mailer] [DX] Introduce debug command Dec 20, 2020
@gmorel gmorel force-pushed the feature/5.x_mailer_debug_command branch 4 times, most recently from 5e6b394 to 00f7a2b Compare December 21, 2020 10:35
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
switch ($input->getOption('body-source')) {
Copy link
Author

Choose a reason for hiding this comment

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

@gmorel gmorel force-pushed the feature/5.x_mailer_debug_command branch 2 times, most recently from 6d29758 to a899719 Compare December 21, 2020 10:46
@gmorel gmorel changed the title [Mailer] [DX] Introduce debug command [Mailer] [DX] Introduce send email command Dec 21, 2020
@gmorel gmorel force-pushed the feature/5.x_mailer_debug_command branch 2 times, most recently from 8482ac1 to 796349b Compare December 21, 2020 11:00
gmorel added a commit to gmorel/symfony-docs that referenced this pull request Dec 21, 2020
@@ -5,6 +5,8 @@ CHANGELOG
-----

* added the `mailer` monolog channel and set it on all transport definitions
* added `console mailer:send-email` command to check if your mailer configuration or supplier is (still) operational
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* added `console mailer:send-email` command to check if your mailer configuration or supplier is (still) operational
* added `mailer:send-email` command to check if your mailer configuration or supplier is (still) operational

- <info>php %command.full_name% [email protected] [email protected]</info>
- <info>php %command.full_name% [email protected] [email protected] --subject=Test --body=body</info>

You can get body of message from a file:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
You can get body of message from a file:
Use a file for the body:

Aim is to allow to test if your mailer configuration or supplier is operational in production

Usage
- console mailer:send-email [email protected] [email protected]
- console mailer:send-email [email protected] [email protected] --subject=Test --body=body
- console mailer:send-email [email protected] [email protected] --subject=Test --body-source=file --body=/path/to/file
@gmorel gmorel force-pushed the feature/5.x_mailer_debug_command branch from 796349b to 7d3f884 Compare December 21, 2020 11:49
@chalasr
Copy link
Member

chalasr commented Dec 21, 2020

Be careful here, this has been proposed several times and rejected: #37409. Better wait for @fabpot' thoughts before moving forward.

@gmorel
Copy link
Author

gmorel commented Dec 21, 2020

Thanks @chalasr, I didn't see it.

@gmorel
Copy link
Author

gmorel commented Dec 21, 2020

I close the PR in order to avoid unnecessary pressure to @fabpot.
Feel free to re-open it if you change your mind.

@gmorel gmorel closed this Dec 21, 2020
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
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.

7 participants