3
I’m using Javamail for sending email, with attachment, on Android.
When attaching a file with extension ". txt" it is assigning the content to the body of the email, not as attached file.
My file attachment code:
public void addAttachment(String filename) throws Exception {
DataSource file = new FileDataSource(filename);
BodyPart attachment = new MimeBodyPart();
attachment.setDataHandler(new DataHandler(file));
attachment.setFileName(filename);
multipart.addBodyPart(attachment);
}
I did a test by changing the file extension to ". Tx" and the same came attached as file. How do I attach the ". txt" as file?
didn’t work. Keeps coming in the body of the email. Any other suggestions?
– felipearon
@felipearon, try adding the application/octet-stream mimetype. Check updated response.
– Fernando Leal
gave error: Ioexception while sending message; javax.activation.Unsupporteddatatypeexception: no Object DCH for MIME type application/octet-stream
– felipearon
@felipearon, see edition in reply.
– Fernando Leal
that way it worked, just like I mentioned in Dante’s answer. Only detail is that visualizing by Thunderbird it shows in the body and not as an attachment.
– felipearon
@felipearon, dai already believe that it is particularities of each email manager, in handling the attachments.
– Fernando Leal