使用Mailgun发送电子邮件-未找到Java类型FormDataMultiPart和MIME媒体类型application/x-www-form-urlencoded的邮件正文编写器

使用Mailgun发送电子邮件-未找到Java类型FormDataMultiPart和MIME媒体类型application/x-www-form-urlencoded的邮件正文编写器,java,android,jersey,mailgun,Java,Android,Jersey,Mailgun,我正在尝试使用Mailgun和Jersey从android应用程序发送电子邮件。问题是,当我发布请求以获取响应时,应用程序崩溃并出现错误:找不到Java类型的消息体编写器class com.sun.jersey.multipart.FormDataMultiPart和MIME媒体类型application/x-www-form-urlencoded。我不知道为什么会这样。对此进行研究后,有人建议您在创建客户机时添加multipart类,但这也不起作用。请注意,在这封电子邮件中,它只是纯文本,但我

我正在尝试使用Mailgun和Jersey从android应用程序发送电子邮件。问题是,当我发布请求以获取响应时,应用程序崩溃并出现错误:
找不到Java类型的消息体编写器class com.sun.jersey.multipart.FormDataMultiPart和MIME媒体类型application/x-www-form-urlencoded
。我不知道为什么会这样。对此进行研究后,有人建议您在创建客户机时添加multipart类,但这也不起作用。请注意,在这封电子邮件中,它只是纯文本,但我需要在应用程序中发送另一封可能包含附件的电子邮件-0或更多图像

java类:

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
import com.sun.jersey.multipart.FormDataMultiPart;
import com.sun.jersey.multipart.impl.MultiPartWriter;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

ClientConfig cc = new DefaultClientConfig();
cc.getClasses().add(MultiPartWriter.class);
Client theClient = Client.create(cc);
theClient.addFilter(new HTTPBasicAuthFilter("api", "my_api_key"));

final WebResource theWebResource = theClient.resource("https://api.mailgun.net/v3/"
                                                        + "mailgun_domain_key"
                                                        + "/messages");

final FormDataMultiPart message = new FormDataMultiPart();
message.field("from", "My App <donotreply@dnr.com>");
message.field("to", "email_recs");
message.field("subject", "subj");
message.field("text", "body_text");

ClientResponse response = theWebResource.type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class, message);
//app crashes after the above line is executed
看看这个

theWebResource.type(MediaType.APPLICATION_FORM_URLENCODED)    
您试图发布一个要用作多部分请求的对象,
FormDataMultiPart
,但您正在将
内容类型设置为
application/x-www-form-urlencoded

您只需将
内容类型
更改为
多部分/表单数据
[1]或
MediaType.multipart\u表单数据

一,。如

中所述,看看这个

theWebResource.type(MediaType.APPLICATION_FORM_URLENCODED)    
您试图发布一个要用作多部分请求的对象,
FormDataMultiPart
,但您正在将
内容类型设置为
application/x-www-form-urlencoded

您只需将
内容类型
更改为
多部分/表单数据
[1]或
MediaType.multipart\u表单数据


一,。如

中所述,您解决了问题吗?@user2978188这不再是一个要求-我们不再在应用程序中发送电子邮件,因此我没有解决它,但peeskillet的答案似乎是正确的。你解决了这个问题吗?@user2978188这不再是一个要求-我们不再在应用程序中发送电子邮件,所以我没有解决它,但peeskillet的答案似乎是正确的