jakartaee / mail-api

Jakarta Mail Specification project
https://jakartaee.github.io/mail-api
Other
240 stars 100 forks source link

Getting Exception while calling MimeUtility.encodeText(inputText, "UTF-8", null); #698

Closed dilumonjames93 closed 6 months ago

dilumonjames93 commented 10 months ago

Describe the bug Getting below Exception while calling MimeUtility.encodeText(inputText, "UTF-8", null); with Japanese alphabets

English words are working fine.

Exception in thread "main" java.lang.IllegalStateException: Not provider of jakarta.mail.util.StreamProvider was found at jakarta.mail.util.FactoryFinder.find(FactoryFinder.java:64) at jakarta.mail.util.StreamProvider.provider(StreamProvider.java:177) at jakarta.mail.internet.MimeUtility.doEncode(MimeUtility.java:824) at jakarta.mail.internet.MimeUtility.encodeWord(MimeUtility.java:750) at jakarta.mail.internet.MimeUtility.encodeText(MimeUtility.java:527)

To Reproduce Steps to reproduce the behavior:

  1. Create a sample Java class as below

import jakarta.mail.internet.MimeUtility; import java.io.UnsupportedEncodingException;

public class MimeUtilityExample { public static void main(String[] args) { String inputText = "人件費予算売上リキャッフ"; // Replace with your text try { String encodedText = MimeUtility.encodeText(inputText, "UTF-8", null); System.out.println("Encoded Text: " + encodedText); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } }

  1. add jakarta.mail-api-2.1.2.jar dependancy to the class
  2. just run it
  3. See error

Expected behavior it should encode the string successfully

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Mail server:

Additional context Add any other context about the problem here.

jmehrens commented 8 months ago
  1. add jakarta.mail-api-2.1.2.jar dependancy to the class

There are 4 jars that have to be added: angus-activation-XXX.jar,
angus-mail-XXX.jar jakarta.mail-api-XXX.jar jakarta.activation-api-XXX.jar

Not provider of jakarta.mail.util.StreamProvider was found is due to only adding the API and not the implementation.

lukasj commented 6 months ago

@jmehrens is right - as of 2.1.2, the implementation is not part of the API jar, one has to explicitly which implementation to use, one example can be Angus Mail, which is the follower of the JavaMail/JakartaMail implementation