java - 如何在 Android < 5.0 上使用 Mailgun 发送 HTML 电子邮件

标签 java android mailgun

我正在尝试将 Mailgun 集成到我的 Android 应用程序中,但遇到了很多问题,并且想知道是否有人在 Android 上成功使用 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

因此,我想知道是否有人遇到过这些问题(在低于 5.0 的 Android 设备上使用 Mailgun 和/或发送 HTML 电子邮件)并能够解决这些问题,可以给我一些指导。谢谢!

最佳答案

当您指向官方 Mailgun 文档时,我假设您正在使用 Jersey 1.x 库作为 JAX-RS 客户端。

我建议你尝试一下 2.x 分支。看看at this .

此外,您不需要使用 Jersey。任何 REST 客户端都可以。在 this SO question您有其他选择和更多信息。

现在就开始讨论你的问题了。 Jersey任何 JAX-RS 库都使用提供者来处理不同的事情,包括处理内容(实体)。您的问题似乎是默认的 XML 实体提供程序使用 JAXB 或 JAXP (那些 javax.xml 类),它们在您的类路径中不可用。但是you can provide Jersey with any other entity manager for XML content type 。实际上,当前文档解释了 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>

关于java - 如何在 Android < 5.0 上使用 Mailgun 发送 HTML 电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40094433/

相关文章:

c# - 通过mailgun接收邮件

java - 使用 Maven 父级和模块

Java Stream API 比较数组中的字符串

android - admod 关闭后显示媒体播放器的日志

android studio 无法解析符号 id

php - Mailgun sendMessage参数异常

java - 安卓有bug吗? : String. substring(5).replace (“” , “” )//空字符串

java - Install4j:Windows 安装程序显示 java.lang.LinkageError:ClassCastException

android - 如何获得地板等级

php - 邮件 API 能够按投递时间将邮件分组给发件人