Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. public InputStreamDataSource(InputStream inputStream) {
  2. this.inputStream = inputStream;
  3. }
  4.  
  5. @Override
  6. public InputStream getInputStream() throws IOException {
  7. return inputStream;
  8. }
  9.  
  10. @Override
  11. public OutputStream getOutputStream() throws IOException {
  12. throw new UnsupportedOperationException("Not implemented");
  13. }
  14.  
  15. @Override
  16. public String getContentType() {
  17. return "*/*";
  18. }
  19.  
  20. @Override
  21. public String getName() {
  22. return "InputStreamDataSource";
  23. }
  24.  
  25. MimeBodyPart messageBodyPart = new MimeBodyPart();
  26. messageBodyPart.setContent(message, "text/html");
  27.  
  28. // creates body part for the attachment
  29. MimeBodyPart attachPart = new MimeBodyPart();
  30. String attachFile = attachment.getName();
  31.  
  32. InputStream ipStream=null;
  33. ipStream = attachment.getInputStream();
  34. DataHandler dataHandler = new DataHandler(new InputStreamDataSource(ipStream));
  35. attachPart.setDataHandler(dataHandler);
  36. attachPart.setFileName(attachFile);
  37.  
  38. // adds parts to the multipart
  39. multipart.addBodyPart(messageBodyPart);
  40. multipart.addBodyPart(attachPart);
  41.  
  42. msg.setContent(multipart);
  43. Transport.send(msg);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement