Quick revision
The short answer
Since Jakarta Mail 2.1, which Jakarta EE 10 uses, jakarta.mail-api contains only the API, and the SMTP provider lives in a separate implementation such as Eclipse Angus Mail. With only the API jar, Session finds no provider for the smtp protocol and throws NoSuchProviderException. Old javax.mail or com.sun.mail jars left on the classpath make it worse, because their providers belong to the wrong namespace; on an application server, we should use the server's own mail session instead of bundling jars.
What to remember
In this answer, we saw that NoSuchProviderException for smtp means the session found no SMTP provider, because jakarta.mail-api 2.1 is only the API and the implementation, Eclipse Angus Mail, must be added. Leftover javax.mail or com.sun.mail jars cause classes and providers to come from the wrong namespace, so we inspect and clean the dependency tree. On an application server, we use the server's mail session through JNDI and mark the API as provided, and a GreenMail integration test keeps the problem from returning.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Since Jakarta Mail 2.1, which Jakarta EE 10 uses, jakarta.mail-api contains only the API, and the SMTP provider lives in a separate implementation such as Eclipse Angus Mail. With only the API jar, Session finds no provider for the smtp protocol and throws NoSuchProviderException. Old javax.mail or com.sun.mail jars left on the classpath make it worse, because their providers belong to the wrong namespace; on an application server, we should use the server's own mail session instead of bundling jars.
Why this question is asked
This failure is a classic of the Java EE to Jakarta EE move. The code compiles, the tests that mock the mail sender pass, and the first real email in a test environment fails. Interviewers ask it because the answer shows whether we understand the difference between an API and its implementation, how Java discovers providers at runtime, and how to read a dependency tree. In this answer, we will recap how Jakarta Mail finds its providers, reproduce the error, see why mixed namespaces cause trouble, fix it for standalone and application server deployments, and add a test that catches it in CI.
1How Jakarta Mail Finds a Provider
Jakarta Mail separates what we call from what does the work. We call Session, MimeMessage and Transport, which are in the API. The code that speaks SMTP, IMAP or POP3 is a provider: a class such as an SMTP transport that the session loads at runtime by protocol name. When we call Transport.send or session.getTransport("smtp"), the session looks up which class is registered for smtp and instantiates it.
Providers are registered by the implementation jar, through Java's ServiceLoader mechanism and provider configuration files inside the jar. In Java EE 8, the usual artifact (javax.mail from com.sun.mail) bundled API and implementation in one jar, so the provider was always there. Starting with Jakarta Mail 2.1, the API artifact jakarta.mail:jakarta.mail-api ships without any provider, and the implementation moved to Eclipse Angus Mail (org.eclipse.angus:angus-mail). So a project that just replaced javax.mail with jakarta.mail-api now has an API with nobody behind it.
- Our codeSession,
MimeMessage,Transport.send - jakarta.mail-api 2.1+API classes only, no protocol providers
- angus-mailSMTP, IMAP, POP3 providers, registered for discovery
- Jakarta Activation (and Angus Activation)Data handlers for MIME types
4 layers, from the top down. Step through them one at a time.
Without the implementation layer, the session has no class to load for smtp.
2Reproducing the Error
A build with only the API dependency compiles and starts. The failure appears only at the moment we send.
Notice that nothing is wrong with our code. The session simply has no class registered for smtp, so it reports that the provider does not exist.
3Why Mixed javax and jakarta Jars Make It Worse
During a migration, old jars often remain through transitive dependencies, for example com.sun.mail:javax.mail pulled in by an old reporting library, or com.sun.mail:jakarta.mail 2.0, which used the jakarta namespace but predates the API and implementation split. These jars carry their own provider registrations and their own classes.
The result depends on which jar the class loader sees first. A provider compiled against javax.mail.Transport is not a jakarta.mail.Transport, so the session cannot use it, and we may see NoSuchProviderException, a ClassCastException or a NoClassDefFoundError. Two versions of the jakarta API, for example 2.0 and 2.1, can also conflict. So the rule is one namespace and one implementation, and we find the strays in the dependency tree.
Any com.sun.mail artifact or javax.mail artifact is a candidate for exclusion. We exclude it from the library that brings it in, and if that library really needs javax.mail at runtime, we upgrade the library to a version built for jakarta.
4Fix 1: Add the Implementation for a Standalone Application
When the application ships its own libraries, for example a Spring Boot jar or a plain Java service, we add Angus Mail next to the API. In Spring Boot 3 and later, spring-boot-starter-mail already brings in the Angus implementation, so adding the starter instead of individual jars avoids the problem.
5Fix 2: Use the Server's Mail Session on an Application Server
On a Jakarta EE 10 application server such as WildFly, Open Liberty or Payara, the server already provides Jakarta Mail with an implementation. Bundling our own mail jars in the WAR can clash with the server's copy, because two copies of the API classes are then visible to different class loaders. The better approach is to mark the API as provided, so we compile against it but do not package it, and to inject the mail session the server configures, usually bound in JNDI.
Now the host, port, credentials and TLS settings live in the server configuration, and operations can change them without a new build.
6Catching It in CI With GreenMail
The bug escaped because our tests mocked the mail sender, so no real provider was ever loaded. GreenMail is a test library that runs an SMTP server inside the test, which lets us send a real email through the real Jakarta Mail stack and assert that it arrived.
If someone later removes the implementation or a stray javax jar sneaks back in, this test fails in the pipeline instead of in production.
7Follow-up questions
Why did it work on Java EE 8?
Because the common javax.mail artifact from com.sun.mail contained both the API and the implementation, including the SMTP provider, and application servers bundled it as well. The separation into jakarta.mail-api and Angus Mail came with Jakarta Mail 2.1.
Does the same split affect other Jakarta APIs?
Yes, it is the general pattern: Jakarta Activation also moved its implementation to Angus Activation, and JSON-B, JSON-P, JAXB and Bean Validation all have API jars that need an implementation such as Yasson, Parsson, the Glassfish JAXB runtime or Hibernate Validator when we run outside an application server.
How can we confirm which jar a class came from at runtime?
We can log Transport.class.getProtectionDomain().getCodeSource().getLocation() or run the JVM with -verbose:class and search for mail classes. That shows exactly which jar each class was loaded from.
8Conclusion
In this answer, we saw that NoSuchProviderException for smtp means the session found no SMTP provider, because jakarta.mail-api 2.1 is only the API and the implementation, Eclipse Angus Mail, must be added. Leftover javax.mail or com.sun.mail jars cause classes and providers to come from the wrong namespace, so we inspect and clean the dependency tree. On an application server, we use the server's mail session through JNDI and mark the API as provided, and a GreenMail integration test keeps the problem from returning.
Open with
NoSuchProviderException for smtp means the Session could not find any class registered to handle the smtp protocol. On Java EE 8 the usual javax.mail jar contained both the API and the Sun implementation, so the provider was always there.
Then, if they want more
Since Jakarta Mail 2.1, which Jakarta EE 10 uses, jakarta.mail-api is only the API, and the SMTP, IMAP and POP3 providers are in Eclipse Angus Mail, the successor of the reference implementation. So with only the API jar, the code compiles but fails when it sends.
For a standalone or Spring Boot application, I would add angus-mail, or just use spring-boot-starter-mail, which brings it in.
I would also run mvn dependency:tree for com.sun.mail and javax.mail, because old jars pulled in transitively can load classes or providers from the wrong namespace and cause the same error or class cast errors; I would exclude them or upgrade the library that needs them.
If the application runs on an application server like WildFly or Open Liberty, I would not bundle mail jars at all. I would mark the Jakarta EE API as provided and inject the server's mail session with @Resource and its JNDI name, so configuration lives in the server.
Finally, I would add an integration test with GreenMail that sends a real message, so this is caught in CI.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Jakarta EE 10, Spring Boot 3
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Jakarta EE specifications
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "After moving an application from Java EE 8 to Jakarta EE 10, email sending fails with...": https://scrivio-interview-library.netlify.app/java/jakarta-ee-platform/a51fd81158/