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

Bug: withEmailDefaults and withEmailOverrides does not work with CustomMailer #448

Closed
morki opened this issue Mar 1, 2023 · 11 comments
Closed

Comments

@morki
Copy link

morki commented Mar 1, 2023

It is simply ignored.

@bbottema
Copy link
Owner

bbottema commented Mar 1, 2023

Most defaults are set when creating the Email, but overrides happen during sending as well as the defaults for smime/dkim. Those will fail currently.

However, I'm currently working on an overhaul regarding defaults and overrides. And this will be addressed.

@morki
Copy link
Author

morki commented Mar 2, 2023

Thank you for your response. Related issue I am facing is that even with CustomMailer, email is enforced to have From, but it is irrelevant for custom mailer. I thought it can be solved with withEmailOverrides and setting "fake" from address in one place, but it does not work.

I will be happy if in future, it can be addressed somehow. Thank you very much for this awesome library :)

@bbottema bbottema changed the title Enhancement: withEmailDefaults and withEmailOverrides does not work with CustomMailer Bug: withEmailDefaults and withEmailOverrides does not work with CustomMailer Mar 8, 2023
@bbottema bbottema added this to the 8.0.0 milestone Mar 8, 2023
@bbottema
Copy link
Owner

bbottema commented Mar 8, 2023

Btw, as a workaround you can disable the completeness validation using mailerBuilder.disablingAllClientValidation(true).

I gotta ask though, why is From not relevant in your use case? For the purpose of sending emails, in whatever form, according to RFC 5322 the From header is mandatory.

@morki
Copy link
Author

morki commented Mar 8, 2023

I have a logging CustomMailer implementation when there is no SMTP configuration in application.
In this case, FROM is irrelevant and also there is no source for it.

An example in Kotlin:

val mailer = when (smtpUrl) {
    null -> MailerBuilder
        .withCustomMailer(LoggingMailer)
        .disablingAllClientValidation(true)
        .clearEmailValidator()
        .buildMailer()

    else -> MailerBuilder
        .withSMTPServer(smtpUrl.host, smtpUrl.port, smtpUrl.user, smtpUrl.password)
        .withTransportStrategy(TransportStrategy.valueOf(smtpUrl.protocol.name.uppercase()))
        .withSessionTimeout(5000)
        .withEmailOverrides(
            EmailBuilder.startingBlank()
                .from(smtpUrl.parameters.getOrFail("from"))
                .buildEmail()
        )
        .buildMailer()
}!!

@bbottema
Copy link
Owner

bbottema commented Mar 8, 2023

I see. In that case, does .disablingAllClientValidation(true) cover your use case appropriately?

@morki
Copy link
Author

morki commented Mar 8, 2023

Yes, thank you, it is working perfectly now :)

@morki
Copy link
Author

morki commented Mar 8, 2023

The only little improvement for readabolity would be to create an override of .withCustomMailer to accept lambda or maybe make empty default implementation of testConnection in CustomMailer.

But i know it is just cosmetic and readability, so just to note you. Thank you very much for this library :)

@morki morki closed this as completed Mar 8, 2023
@morki
Copy link
Author

morki commented Mar 8, 2023

Oh sorry, the solution with disableAllClientValidation(true) does not work. I only forget to remove my current workaround (setting manualy .from("this@is.workaround") from all my e-mail builders.

It throws: Email is not valid: missing sender. Provide with emailBuilder.from(...)

@morki morki reopened this Mar 8, 2023
@bbottema
Copy link
Owner

bbottema commented Mar 8, 2023

Ahh indeed, I just checked the code and the completeness check is always performed. I will disable this along with the other validations in case of .disableAllClientValidation(true). Expect a release soon.

@morki
Copy link
Author

morki commented Mar 8, 2023

Thank you very much :)

@bbottema
Copy link
Owner

bbottema commented Mar 8, 2023

I released 8.0.0, which now should always apply defaults and overrides in all scenarios. Please let me know if you run into any issue. Note, I'm still in the process of updating the documentation on simplejavamail.org.

@bbottema bbottema closed this as completed Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants