Advertisement
amigleon92

Untitled

Sep 3rd, 2018
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1.  
  2. private void inicializarMail() throws Exception {
  3. //smtp.gmail.com
  4. //String host = "asusisv-lvsldap.sis.personal.net.py";
  5. //String port = "25";
  6.  
  7. Properties props = new Properties();
  8. if(params.getText("mail.host")==null){
  9. throw new Exception("El host del mail es nulo.");
  10. }
  11. if(params.getText("mail.port")==null){
  12. throw new Exception("El puerto del mail es nulo.");
  13. }
  14. props.put("mail.smtp.host", params.getText("mail.host"));
  15. props.put("mail.smtp.port", params.getText("mail.port"));
  16. //props.put("mail.smtp.ssl.trust", "correo.snna.gov.py");
  17.  
  18. mailSession = Session.getInstance(props);
  19. }
  20.  
  21. private void enviarMail(String asunto, String remitente, String destinatario,
  22. String contentType) throws IOException, MessagingException {
  23. try{
  24. //Crear archivo...
  25. String nombreArchivo = "reporte.html";
  26. String ruta = "";
  27. File archivo = new File(ruta+nombreArchivo);
  28. BufferedWriter bw = new BufferedWriter(new FileWriter(ruta+nombreArchivo));
  29. bw.write(generarInforme());
  30. bw.close();
  31.  
  32. BodyPart texto = new MimeBodyPart();
  33. texto.setText("________________________________\n\nAVISO LEGAL: Esta información es privada y confidencial y está dirigida únicamente a su destinatario. Si usted no es el destinatario original de este mensaje y por este medio pudo acceder a dicha información por favor elimine el mensaje. La distribución o copia de este mensaje está estrictamente prohibida. Esta comunicación es sólo para propósitos de información y no debe ser considerada como propuesta, aceptación ni como una declaración de voluntad oficial de NUCLEO S.A. La transmisión de e-mails no garantiza que el correo electrónico sea seguro o libre de error. Por consiguiente, no manifestamos que esta información sea completa o precisa. Toda información está sujeta a alterarse sin previo aviso.\n\nThis information is private and confidential and intended for the recipient only. If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited. This communication is for information purposes only and shall not be regarded neither as a proposal, acceptance nor as a statement of will or official statement from NUCLEO S.A. Email transmission cannot be guaranteed to be secure or error-free. Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such. All information is subject to change without notice.");
  34.  
  35. BodyPart adjunto = new MimeBodyPart();
  36. adjunto.setDataHandler(new DataHandler(new FileDataSource(ruta+nombreArchivo)));
  37. adjunto.setFileName(nombreArchivo);
  38.  
  39. MimeMultipart multiParte = new MimeMultipart();
  40. multiParte.addBodyPart(texto);
  41. multiParte.addBodyPart(adjunto);
  42.  
  43. MimeMessage m = new MimeMessage(mailSession);
  44. m.setContent(multiParte);
  45.  
  46. Address from = new InternetAddress(remitente);
  47. InternetAddress[] to = InternetAddress.parse(destinatario);
  48.  
  49. m.addRecipients(Message.RecipientType.TO, to);
  50. m.setSubject(asunto);
  51. m.setSentDate(new java.util.Date());
  52. m.setFrom(from);
  53.  
  54. Transport.send(m);
  55. logger.info("Mail enviado");
  56. System.out.println("Mail enviado");
  57.  
  58. //archivo.delete();//Eliminacion de archivo adjunto
  59.  
  60. } catch (Exception e) {
  61. e.printStackTrace();
  62. logger.error("[ERROR AL ENVIAR EL MAIL]: " + e.getMessage());
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement