如何在 Android < 5.0 上使用 Mailgun 发送 HTML 电子邮件
How to send HTML emails with Mailgun on Android < 5.0
我正在尝试将 Mailgun 集成到我的 Android 应用程序中,但我 运行 遇到了很多问题,想知道是否有人在 [=22] 上成功使用过 Mailgun =] 可以提供一些帮助。我可以按照 Mailgun 用户手册 (https://documentation.mailgun.com/user_manual.html#sending-via-api) 发送纯文本电子邮件,但前提是设备的 Android 版本至少是 Lollipop。任何具有较低 Android 版本的设备,我都会收到许多关于丢失 XML 相关 类 的错误,我无法解决,因为我无法导入 javax.*
类。当我尝试使用用户指南中概述的代码发送 HTML 电子邮件时,也会发生同样的情况。
日志中收到的错误示例:
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
因此,我想知道是否有人 运行 遇到这些问题(在 Android 设备 < 5.0 and/or 上使用 Mailgun 发送 HTML 电子邮件)并且能够解决它们可以给我一些指点。谢谢!
当您指向官方 Mailgun 文档时,我假设您正在使用 Jersey 1.x 库作为 JAX-RS 客户端。
我建议您试试 2.x 分支。看看at this.
此外,您不需要使用 Jersey。任何 REST 客户端都可以。在 this SO question 中,您有其他选择和更多信息。
现在进入你的问题。 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。它甚至被编译为依赖项。
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>2.23.2</version>
</dependency>
你可以直接使用 this library.
您还需要将 'configurations' 添加到 gradle 文件中,它应该如下所示:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'net.sargue:mailgun:1.3.2'
}
configurations {
compile.exclude group: 'javax.inject', module: 'javax.inject'
}
更多信息here
我正在尝试将 Mailgun 集成到我的 Android 应用程序中,但我 运行 遇到了很多问题,想知道是否有人在 [=22] 上成功使用过 Mailgun =] 可以提供一些帮助。我可以按照 Mailgun 用户手册 (https://documentation.mailgun.com/user_manual.html#sending-via-api) 发送纯文本电子邮件,但前提是设备的 Android 版本至少是 Lollipop。任何具有较低 Android 版本的设备,我都会收到许多关于丢失 XML 相关 类 的错误,我无法解决,因为我无法导入 javax.*
类。当我尝试使用用户指南中概述的代码发送 HTML 电子邮件时,也会发生同样的情况。
日志中收到的错误示例:
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
因此,我想知道是否有人 运行 遇到这些问题(在 Android 设备 < 5.0 and/or 上使用 Mailgun 发送 HTML 电子邮件)并且能够解决它们可以给我一些指点。谢谢!
当您指向官方 Mailgun 文档时,我假设您正在使用 Jersey 1.x 库作为 JAX-RS 客户端。
我建议您试试 2.x 分支。看看at this.
此外,您不需要使用 Jersey。任何 REST 客户端都可以。在 this SO question 中,您有其他选择和更多信息。
现在进入你的问题。 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。它甚至被编译为依赖项。
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
<version>2.23.2</version>
</dependency>
你可以直接使用 this library.
您还需要将 'configurations' 添加到 gradle 文件中,它应该如下所示:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'net.sargue:mailgun:1.3.2'
}
configurations {
compile.exclude group: 'javax.inject', module: 'javax.inject'
}
更多信息here