I'm trying to do an Android app that sends an image automatically without any intervention from the user.
I'm using javax.mail jar (and the activation.jar and additional.jar) in order to do so.
I'm doing the 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 I execute this code, I get the 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 for MIME type multipart/mixed;
W/System.err(24907): boundary="----=_Part_0_1095625208.1397499270313"
W/System.err(24907): at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1182)
W/System.err(24907): at javax.mail.Transport.send0(Transport.java:254)
W/System.err(24907): at javax.mail.Transport.send(Transport.java:124)
Any idea on how can I solve this?
I'm using a Debian 64-bits computer and Eclipse Java EE IDE for Web Developers - Kepler. if it's needed for the solution...