android - Sending email with Mailgun - a message body writer for Java type FormDataMultiPart and MIME media type application/x-www-form-urlencoded was not found -


i attempting send email android app using mailgun , jersey. problem when post request response, app crashes error: a message body writer java type, class com.sun.jersey.multipart.formdatamultipart, , mime media type, application/x-www-form-urlencoded, not found. not sure why case. researching suggested add multipart class when creating client, did not work either. note in email plain text, need send email in app may contain attachments - 0 or more images.

java class:

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 above line executed 

build.gradle (module):

apply plugin: 'com.android.application'  android {     compilesdkversion 21     buildtoolsversion "21.1.2"      defaultconfig {         applicationid "com.x.x"         minsdkversion 14         targetsdkversion 21         versioncode 1         versionname "1.0"     }     buildtypes {         release {             minifyenabled false             proguardfiles getdefaultproguardfile('proguard-android.txt'), 'proguard-rules.pro'         }     }      packagingoptions{         pickfirst 'meta-inf/jersey-module-version'         pickfirst 'meta-inf/services/com.sun.jersey.spi.inject.injectableprovider'         pickfirst 'meta-inf/services/javax.ws.rs.ext.messagebodyreader'         pickfirst 'meta-inf/services/javax.ws.rs.ext.messagebodywriter'     } }  dependencies {     compile filetree(dir: 'libs', include: ['*.jar'])     compile 'com.android.support:appcompat-v7:21.0.3'     compile 'com.parse.bolts:bolts-android:1.+'     compile filetree(dir: 'libs', include: 'parse-*.jar')     compile files('libs/jersey-client-1.19.jar')     compile files('libs/jersey-core-1.19.jar')     compile files('libs/jersey-multipart-1.19.jar')     compile files('libs/javax.ws.rs.jar')     compile files('libs/jai_imageio-1.1.jar') } 

look @

thewebresource.type(mediatype.application_form_urlencoded)     

you're trying post object meant used multipart request, formdatamultipart, setting content-type application/x-www-form-urlencoded.

you need change content-type multipart/form-data[1] or mediatype.multipart_form_data.

1. mentioned in api documentation


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -