code_junkie

How do I send a binary attachment in an email with Java using the JavaMail API?

Nov 11th, 2011
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. MimeMultipart messageContent = new MimeMultipart();
  2.  
  3. BodyPart bodyPart = new MimeBodyPart();
  4. DataSource source = new FileDataSource(yourFile);
  5. bodyPart.setDataHandler(new DataHandler(source);
  6. bodyPart.setFileName("MyFile.ext");
  7. bodyPart.setDisposition(Part.ATTACHMENT);
  8.  
  9. // Then add to your message:
  10. messageContent.addBodyPart(bodyPart);
Add Comment
Please, Sign In to add comment