-
-
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
Enhancement: add native support for overriding envelope-level receiver(s) #483
Comments
Thanks for reporting @andrus. Let's have a look.
Well, since Simple Java Mail is not the one sending the mail anymore, there is no relevant server config. In fact, that method used to validate the data like mandatory host, which makes no sense if you use your own implementation (aside from that, this method is documented as for internal use). However, I understand you have a use case here, so let's look at that.
So really, your custom implementation wants to send it with Simple Java Mail still, so why not just use a separate Mailer and move the server config there? |
Thanks for the quick reply!
This may actually work! Instead of fighting with |
Ok, that's not what I intended :D - I thought you might just configure two mailers separately. One properly configured for everything but sending, but with custom mailer allowing you to do any overrides. And then a dumb sender that you relay the modified Email to (possibly configured as a cluster). But still, let me know how your experiment turns out :) |
Unfortunately, Email object does not have a "recipient override" property. With Email, I can wipe out "to/cc/bcc", and replace them with the "override" address, but that does not allow the recipient of the "overridden" message (e.g. a QA team member) to inspect how the original email would have looked like without the override. That's why I need to mess with the transport directly. |
Can you share the code you used before this? I'm not sure I follow the semantics of your override use-case. |
Essentially, I am taking advantage of the difference between the SMTP "envelope" destination addresses and the addresses in the message itself. Overriding the former, and preserving the latter allows to create a nice test experience. |
Hhm, the current version of TransportRunner doesn't even support recipients separately, so this won't even fly. I'd have to think deeply about allowing some way of interception or overriding behaviour. The Custom Mailer concept wasn't designed or meant for affecting existing internal behaviour; it was meant to replace it with your own. |
Thinking out loud, the problem with this is that 'overriding' behaviour can apply to every step of the mailing process. So do I devise some kind of step-filter concept, where each step a filter can be inserted. Or do I approach this from very specific use cases (such as your) and devise a solution for that. |
I have only a superficial familiarity with all the mail RFCs, but it seems like providing a model that describes all possible properties (e.g. explicit properties of the SMTP "envelope" on the |
I think I have a clear understanding now and I'm looking at some solutions, but I'm still a little confused as to why you need |
Good question. It didn't fail before. I just pushed a branch with my attempt to upgrade the existing code base to 8.x, and if you run https://github.com/bootique/bootique-simplejavamail/tree/8 |
I'm not able to build it with Maven 3.8.6. What version are you on? Actually, just a stacktrace will do for me. |
It builds for me on Mac with either 3.8.x or 3.9.x versions of Maven, Java 11, 17, 21. Master should build successfully, branch 8 should result in a unit test failure. |
If you could provide a stack trace, then that's enough I think. |
What happens is that instead of the preconfigured Mailer, in the presence of CustomMailer shown on that branch, SJM implicitly creates a new stack with default settings, and then the exception is caused by the attempt to connect to
|
Ok well, I'll leave that for what it is for the moment 😅 I've released 8.4.0, which includes the override receivers feature, see documentation here. |
That did it. I was able to implement a Mailer decorator that does not require transport hacking. Way cleaner than before. Thanks!! |
This looks great! And it seems this is not just for testing. Amazon SES strongly suggests you to send messages with one api call per recipient (https://aws.amazon.com//blogs/messaging-and-targeting/how-to-send-messages-to-multiple-recipients-with-amazon-simple-email-service-ses/). Am I correct in assuming this will make it possible to adhere to that guideline and have the e.g. the to-field contain all the recipients? |
I think the SMTP protocol makes sure each envelope recipient is handled separately. It may be a single SMTP session, but multiple send actions on the protocol level. |
I am trying to upgrade Bootique integration of SJM from 7.4.0 to 8.x, but the custom mailer can no longer obtain the preconfigured SJM Mailer. Somewhere along the way
MailerRegularBuilderImpl.buildServerConfig()
started returning null when there is a custom mailer present. So that code that worked previously stopped working.An earlier issue #375 expalins the motivation for this particular custom mailer. Its goal is not to have a fully custom transport, but rather to override recipients at the transport level without changing to/cc/bcc of the original message. So I would very much want to reuse SJM transport. Having said that, I do feel like using a custom mailer for my purpose is too fragile, and I'd rather there was an option in the EmailBuilder to provide "recipient override" address for testing.
The text was updated successfully, but these errors were encountered: