Reputation: 305
I'm trying to integrate Mailgun into my Android application, but I'm running into a lot of issues, and was wondering if anyone who has successfully used Mailgun on Android can provide some help. I am able to send plain text emails following the Mailgun user manual (https://documentation.mailgun.com/user_manual.html#sending-via-api), but only if the Android version of the device is at least Lollipop. Any device with a lower Android version, I receive many errors regarding missing XML-related classes, which I cannot resolve since I cannot import javax.*
classes. The same happens when I try to send HTML email using the code outlined in the user guide.
Example of errors received in log:
The provider class, class com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$App, could not be instantiated.
Processing will continue but the class will not be utilized
java.lang.TypeNotPresentException: Type javax.xml.stream.XMLInputFactory not present
The provider class, class com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$Text, could not be instantiated.
Processing will continue but the class will not be utilized
java.lang.TypeNotPresentException: Type javax.xml.stream.XMLInputFactory not present
The provider class, class com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General, could not be instantiated.
Processing will continue but the class will not be utilized
java.lang.TypeNotPresentException: Type javax.xml.stream.XMLInputFactory not present
Thus, I am wondering if anyone who has ran into these issues (using Mailgun on Android devices < 5.0 and/or sending HTML emails) and were able to solve them can give me some pointers. Thanks!
Upvotes: 0
Views: 457
Reputation: 1417
You can just use this library.
Also you need to add 'configurations' to your gradle file and it should look like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'net.sargue:mailgun:1.3.2'
}
configurations {
compile.exclude group: 'javax.inject', module: 'javax.inject'
}
More information here
Upvotes: 0
Reputation: 5875
As you are pointing the official Mailgun documentation I assume you are using Jersey 1.x library as a JAX-RS client.
I suggest you give the 2.x branch a try. Take a look at this.
Also, you are not required to use Jersey. Any REST client will do. In this SO question you have alternative options and more information.
Now exactly into your problem. Jersey and any JAX-RS library uses providers for differents things including dealing with content (entities). It seems your problem is that the default XML entity provider uses JAXB or JAXP (those javax.xml
classes) which is not available in your classpath. But you can provide Jersey with any other entity manager for XML content type. Actually, the current documentation explains how to use MOXy as an alternate JAXB implementation. It is even compiled as a dependency.
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>2.23.2</version>
</dependency>
Upvotes: 2