Skip to content

Bug: wrong username property used when password authentication is not needed #429

Closed

Description

@denisrdasilva

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!

Activity

  1. bbottema commented on Dec 25, 2022

    @bbottema
    Owner

    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.

  2. bbottema commented on Dec 25, 2022

    @bbottema
    Owner

    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.

  3. changed the title [-]Possible Bug[/-] [+]Wrong username property used when password authentication is not needed[/+] on Dec 25, 2022
  4. added a commit that references this issue on Dec 25, 2022
  5. changed the title [-]Wrong username property used when password authentication is not needed[/-] [+]Bug: wrong username property used when password authentication is not needed[/+] on Dec 25, 2022
  6. added this to the 7.5.2 milestone on Dec 25, 2022
  7. bbottema commented on Dec 25, 2022

    @bbottema
    Owner

    Release fix in 7.5.2. Give it a spin!

  8. denisrdasilva commented on Dec 26, 2022

    @denisrdasilva
    Author
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions