You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
and found that Apache commons-email library was not upgraded. This is an issue for example when you are using attachments with a jakarta.activation.DataSource.
This is not a drop-in replacement unfortunately. I had to replace org.apache.commons.mail.EmailException with org.apache.commons.mail2.core.EmailException and
org.apache.commons.mail.HtmlEmail with org.apache.commons.mail2.jakarta.HtmlEmail. Probably there are more replacements needed.
Gemini gave me this list:
You're right to be thorough when migrating from Apache Commons Email 1.x to 2.x, especially the Jakarta EE-compatible version. While the core functionality remains similar, there are package changes and some API adjustments.
Here's a breakdown of the key changes and a guide to updating your code:
Dependency Update
As discussed previously, ensure you've replaced your old commons-email dependency with:
XML
The most significant change is the package namespace. For the Jakarta EE version, all classes are now under org.apache.commons.mail2.jakarta.
3. Key Class Replacements
Here's a list of the most commonly used classes and their updated counterparts:
The most efficient way to update your code is to use your IDE's "Find and Replace in Files" feature.
Search for org.apache.commons.mail. and replace it with org.apache.commons.mail2.jakarta..
And after complaining
You are absolutely correct, and I apologize for that oversight. The package changes in Commons Email 2.x go beyond just the root org.apache.commons.mail to org.apache.commons.mail2.jakarta or org.apache.commons.mail2.core.
You've highlighted a critical point: org.apache.commons.mail.EmailException is indeed moved to org.apache.commons.mail2.core.EmailException.
Revised Find and Replace Strategy
Given the more complex package structure in Commons Email 2.x, a more precise find-and-replace strategy is needed:
Jakarta-Specific Replacements:
Find: org.apache.commons.mail.
Replace: org.apache.commons.mail2.jakarta.
This will handle the core email classes.
Core Exception Replacement:
Find: org.apache.commons.mail.EmailException
Replace: org.apache.commons.mail2.core.EmailException
This will handle the exception class.
Resolver Replacements:
Find: org.apache.commons.mail.resolver.
Replace: org.apache.commons.mail2.jakarta.resolver.
Other Exceptions:
Carefully review any other exceptions that are used. There is a chance that other exceptions were also moved to the core package.
I ran
and found that Apache commons-email library was not upgraded. This is an issue for example when you are using attachments with a jakarta.activation.DataSource.
should be replaced with:
This is not a drop-in replacement unfortunately. I had to replace org.apache.commons.mail.EmailException with org.apache.commons.mail2.core.EmailException and
org.apache.commons.mail.HtmlEmail with org.apache.commons.mail2.jakarta.HtmlEmail. Probably there are more replacements needed.
Gemini gave me this list:
And after complaining
CC @melloware
The text was updated successfully, but these errors were encountered: