Advertisement
Guest User

Untitled

a guest
Apr 4th, 2017
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. Properties props= new Properties();
  2. String host= "express-relay.jangosmtp.net";
  3.  
  4. Session sessione;
  5. final String username="";
  6. String user= "";
  7. String pass="";
  8. final String password="";
  9. Message m;
  10. String from= "boooomber@gmail.com";
  11. String to= "";
  12. String ob="ProvaAllegato";
  13. String text="ole";
  14. String file="voucher.pdf";
  15.  
  16. public void inviamail( ){
  17. props.put("mail.smtp.auth", "true");
  18. props.put("mail.smtp.host", host);
  19. sessione = Session.getInstance(props, new Authenticator(){
  20. protected PasswordAuthentication getPasswordAuthentication(){
  21. return new PasswordAuthentication(username,password);
  22. }
  23. });
  24.  
  25.  
  26. try{
  27. m= new MimeMessage(sessione);
  28.  
  29. m.setFrom(new InternetAddress(from));
  30. m.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
  31. m.setSubject(this.ob);
  32. //m.setText(text);
  33. BodyPart messageB= new MimeBodyPart();
  34. messageB.setText(text);
  35. Multipart multipart= new MimeMultipart();
  36. multipart.addBodyPart(messageB);
  37. messageB= new MimeBodyPart();
  38. DataSource source= new FileDataSource(file);
  39. messageB.setDataHandler(new DataHandler(source));
  40. messageB.setFileName(file);
  41. multipart.addBodyPart(messageB);
  42. m.setContent(multipart);
  43.  
  44.  
  45.  
  46.  
  47. //m.setText(text);
  48. Transport.send(m);
  49. System.out.println("inviata");
  50.  
  51.  
  52.  
  53. }catch(Exception e){
  54. e.printStackTrace();
  55.  
  56. }
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement