jakartaee / jakartaee/mail-api
Authentication issues trying to access POP mailbox
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 285
- Forks
- 109
- Avg merge
- 15h 19m
- Merged PRs (30d)
- 1
Description
**Edit**: I just realized that I'm using angus-mail:1.0.0 . I'm sorry if this is the wrong place to be posting my issue.
I'm trying to access my Office365 Outlook mailbox. I've attempted to authenticate via two-legged OAuth as well as just basic auth. Nonetheless, I hit similar errors. In the case of OAuth
```
jakarta.mail.AuthenticationFailedException: Authentication failure: unknown user name or bad password.
```
and in the case of basic auth
```
jakarta.mail.AuthenticationFailedException: Logon failure: unknown user name or bad password.
```
I'm guessing there's something simple that I'm doing incorrectly but I haven't been able to find any relevant code examples. My code is pasted below
```
package mail;
import jakarta.mail.Authenticator;
import jakarta.mail.PasswordAuthentication;
import jakarta.mail.Session;
import jakarta.mail.Store;
import java.io.IOException;
import java.util.Properties;
public class JavaMailUtil {
public static void accessMailOauth() throws Exception{
System.out.println("Starting...");
// Load OAuth settings
final Properties oAuthProperties = new Properties();
try {
oAuthProperties.load(JavaMailUtil.class.getResourceAsStream("oAuth.properties"));
} catch (IOException e) {
System.out.println("Unable to read OAuth configuration. Make sure you have a properly formatted oAuth.properties file. See README for details.");
return;
}
final String appId = oAuthProperties.getProperty("app.id");
final String[] appScopes = oAuthProperties.getProperty("app.scopes").split(",");
final String clientSecret = oAuthProperties.getProperty("app.clientSecret");
final String authority = oAuthProperties.getProperty("app.authority");
// Get an access token
Authentication.initialize(appId, authority, clientSecret);
final String accessToken = Authentication.getUserAccessToken(appScopes);
System.out.println("Access token = " + accessToken);
String myAccountEmail = "myemail@myemail.onmicrosoft.com";
Properties properties = new Properties();
properties.setProperty("mail.store.protocol", "pop3s");
properties.setProperty("mail.pop3s.auth", "true");
properties.setProperty("mail.pop3s.auth.mechanisms", "XOAUTH2");
properties.setProperty("mail.pop3s.host", "outlook.office365.com");
properties.setProperty("mail.pop3s.port", "995");
properties.setProperty("mail.pop3s.auth.xoauth2.two.line.authentication.format", "true");
Session session = Session.getInstance(properties);
session.setDebug( true );
final Store store = session.getStore();
store.connect(myAccountEmail, accessToken);
System.out.println("Connected to store successfully!!");
}
public static void accessMailBasicAuth() throws Exception{
System.out.println("Starting with Basic Auth...");
String myAccountEmail = "myemail@myemail.onmicrosoft.com";
Properties passwordProperties = new Properties();
passwordProperties.setProperty("mail.store.protocol", "pop3s");
passwordProperties.setProperty("mail.pop3s.host", "outlook.office365.com");
passwordProperties.setProperty("mail.pop3s.port", "995");
passwordProperties.setProperty("mail.pop3s.auth.xoauth2.disable", "true");
Session passwordSession = Session.getInstance(passwordProperties, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(myAccountEmail, "examplepassword");
}
});
passwordSession.setDebug( true );
final Store store = passwordSession.getStore();
store.connect(myAccountEmail, "examplepassword");
System.out.println("Connected to store successfully!!");
}
public static void main(String[] args) throws Exception {
JavaMailUtil.accessMailBasicAuth();
}
}
```
I think I have everything properly setup on the Azure Active Directory and mailbox settings side but any suggestions are welcome.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the README and the two entry points shown in the report: accessMailOauth and accessMailBasicAuth. Review the POP3S properties, OAuth settings, and Store.connect calls, then reproduce the reported failures with the configured Office365 mailbox. Done means identifying whether the behavior is a project defect or a configuration/support issue and documenting the conclusion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- authentication
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100