-
-
Notifications
You must be signed in to change notification settings - Fork 271
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
Debug mode that logs but doesn't send emails? #64
Comments
That doesn't make sense to me. You should probably be use a MailSender mock using something like EasyMock or Mockito. You don't want to test whether Simple Java Mail is working properly, right. |
Sorry, it came out a little wrong. With testing I did not mean testing per-se, like JUnit tests, I meant, for example, in QA environment, it would be preferable to log messages instead of actually sending them. This is not limited to this example either, there are example use cases where "disabling" sending of the email is needed. Our example use case is staging environment. We would like to log the emails instead of actually sending them, but there are two options then - every time sendMail is invoked, in every place check the current environment, or replace mailer with our own class, or use mock SMTP server. Checking for env in every usage of mailer is tedious task at best. Having a mock SMTP isn't a simple task either. Unfortunately sendMail is final and we can't override it. We could in theory create our own interface and two delegates to the mailer, but it introduces an abstraction I would rather avoid having. |
@bbottema do you perhaps have something in mind on how you would prefer to see this in code? I can implement it and send a PR. |
I'm still not sure about the use case validity, because if you want to check environment configuration or integration I would rather configure an actual SMTP server that doesn't relay. However, due to popular demand I will add this feature anyway. I would probably create a Session subclass that overrides |
Implemented, but not ready for release yet. Solution is simple: I've added it as a config property. Either configure through properties file, or set directly on the Mailer. I'll update the documentation somewhere next week. |
mailer.setTransportModeLoggingOnly(true); Or set property simplejavamail.transport.mode.logging.only=true |
Released in v4.2.0. |
Absolutely amazing! Thanks! |
@bbottema Is this feature possible in v5.0+?? Thanks! |
@mordmord It's been available since 4.2.0, so yes it's there :) |
Is it possible to configure mailer to only "pretend" that the mail is sent? TransportStrategy.VOID for example?
Could be rather useful for testing, to not need a smtp server running somewhere.
The text was updated successfully, but these errors were encountered: