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: wrong username property used when password authentication is not needed #429

Closed
denisrdasilva opened this issue Dec 22, 2022 · 4 comments

Comments

@denisrdasilva
Copy link

denisrdasilva commented Dec 22, 2022

Hello! I faced some problem using Simple Java Mail, version 7.5.1, about the prop username.
When passing the prop username, Jakarta Mail does not recognize it. Debugging the code, I found this: in class org.simplejavamail.api.mailer.config.TransportStrategy line 104:

public String propertyNameUsername() {
	return "mail.smtp.username";
}

On the other hand, in jakarta, class jakarta.mail.Service, line 112:

if (protocol != null) {
    if (host == null)
	host = session.getProperty("mail." + protocol + ".host");
    if (user == null)
	user = session.getProperty("mail." + protocol + ".user");
}

Simple Mail uses mail.smtp.username, but Jakarta uses mail.smtp.user. Furthemore, I faced an exception about authentication.

To solve this, I found two ways:

public enum TransportStrategy {
....
	public String propertyNameUsername() {
		return "mail.smtp.user";
	}
       Properties props = new Properties(); 
       props.put("mail.smtp.user", "any_user");
       MailerImpl mailer = (MailerImpl) MailerBuilder
       ....
       .withProperties(props)
      .buildMailer();

So is this problem or is it an error I am causing?

Thanks in advance!

@bbottema
Copy link
Owner

bbottema commented Dec 25, 2022

Hmm, it seems you're on to something. For authenticated SMTP servers this is not an issue, as the property is ignored in that case. For SMTP users that don't require a password though, the property is used and it looks like it is the wrong property. I'm still looking into how this is possible, because that property is a core mechanic since the start of the library. It's possibly one of the least tested functions though (passwordless connections).

I'll get back to this.

@bbottema
Copy link
Owner

bbottema commented Dec 25, 2022

Your use case is a strange one though; either an SMTP sever requires authentication or it doesn't. If it does, a password is required and then everything is fine as I said. However, if there is no authentication needed by the server, the user name is not necessarily required. I suppose it depends on the server implementation how it deals with missing username, but the test server Wiser, which I use in my junit tests, doesn't have any issue no matter the configuration.

The property used in case of missing password is wrong though, so I'll release a new version with the fix for that at least.

@bbottema bbottema changed the title Possible Bug Wrong username property used when password authentication is not needed Dec 25, 2022
bbottema added a commit that referenced this issue Dec 25, 2022
…karta documentation. This is the default user property in case manual authenticator is not used (which is the case with Simple Java Mail if a password was not provided by the user)
@bbottema bbottema changed the title Wrong username property used when password authentication is not needed Bug: wrong username property used when password authentication is not needed Dec 25, 2022
@bbottema bbottema added this to the 7.5.2 milestone Dec 25, 2022
@bbottema
Copy link
Owner

Release fix in 7.5.2. Give it a spin!

@denisrdasilva
Copy link
Author

denisrdasilva commented Dec 26, 2022 via email

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