android - Exception while sending an email in Java with javax.mail -


i'm trying android app sends image automatically without intervention user.

i'm using javax.mail jar (and activation.jar , additional.jar) in order so. i'm doing following

properties props = new properties(); props.put("mail.smtp.auth", true); props.put("mail.smtp.starttls.enable", true); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.ssl.enable",true); props.put("mail.smtp.port", "465");  session session = session.getinstance(props,new authenticator() {     protected passwordauthentication getpasswordauthentication() {     return new passwordauthentication(user,pass);     } });  mimemessage message = new mimemessage(session); message.setfrom(new internetaddress("*******@gmail.com")); message.setsubject("email subject");  message.addrecipient(message.recipienttype.to,                       new internetaddress("******@gmail.com"));  mimebodypart messagebodypart = new mimebodypart(); multipart multipart = new mimemultipart(); multipart.addbodypart(messagebodypart); messagebodypart = new mimebodypart(); messagebodypart.setcontent("<img src=\"image.gif\"/>","text/html"); multipart.addbodypart(messagebodypart); messagebodypart = new mimebodypart(); filedatasource source = new filedatasource(new file(ruta)); messagebodypart.setdatahandler(new datahandler(source)); messagebodypart.setfilename("picture.gif"); messagebodypart.setdisposition("inline"); multipart.addbodypart(messagebodypart); message.setcontent(multipart); transport.send(message); 

when execute code, following error

w/system.err(24907): javax.mail.messagingexception: ioexception while sending message;
w/system.err(24907): nested exception is:
w/system.err(24907): javax.activation.unsupporteddatatypeexception: no object dch mime type multipart/mixed;
w/system.err(24907): boundary="----=_part_0_1095625208.1397499270313"
w/system.err(24907): @ com.sun.mail.smtp.smtptransport.sendmessage(smtptransport.java:1182)
w/system.err(24907): @ javax.mail.transport.send0(transport.java:254)
w/system.err(24907): @ javax.mail.transport.send(transport.java:124)

any idea on how can solve this?

i'm using debian 64-bits computer , eclipse java ee ide web developers - kepler. if it's needed solution...

dch data content handler. mimetype handlers seem not configured correctly.

if can download , use latest 1.5.* version of java mail api, error should getting resolved.

otherwise, within code can execute statements set mimetype handlers.

add following code snippet mail module , available mail session.

mailcapcommandmap mailcapcommandmap = new mailcapcommandmap();  mailcapcommandmap.addmailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed; x-java-fallback-entry=true");  commandmap.setdefaultcommandmap(mailcapcommandmap);  

you can extend additional mimetypes

mailcapcommandmap.addmailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");  mailcapcommandmap.addmailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");  mailcapcommandmap.addmailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");  mailcapcommandmap.addmailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");  

refer to:

apart method, read entire documentation on class.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -