Advertisement
Guest User

Untitled

a guest
Feb 25th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. <p>Ciao,
  2. <br />
  3. in allegato il report dei dati mutui BEI inviati in data ${DATA}.
  4. <br/><br/>
  5. </p>
  6.  
  7. @Service("emailService")
  8. @PropertySource("file:///${jboss.modules.dir}/system/layers/base/it/myCompany/projects/myproject/main/myPropertiesFile.properties")
  9. public class EmailService {
  10.  
  11. // TEST
  12. private static final String[] mailEventiTo = {"test1@gmail.com","test2@gmail.com", "test3@gmail.com"};
  13. private static final String[] mailEventiCc = {"test1@gmail.com","test2@gmail.com", "test3@gmail.com"};
  14.  
  15. private static final String[] mailEccezioneTo = {"test1@gmail.com","test2@gmail.com"};
  16.  
  17. @Autowired
  18. protected JavaMailSender javaMailSender;
  19.  
  20. @Autowired
  21. protected VelocityEngine velocityEngine;
  22.  
  23. @Autowired
  24. private Environment env;
  25.  
  26. private String protocol;
  27. private String auth;
  28. private String tls;
  29. private String ssl;
  30. private String debug;
  31. private String fromEmail;
  32.  
  33. private final String templateFolderReport = "mail/reportBatch";
  34. private final String templateFolderEccezione = "mail/eccezioni";
  35.  
  36. ..........................................................................
  37. ..........................................................................
  38. SOME UTILITY METHODS
  39. ..........................................................................
  40. ..........................................................................
  41.  
  42. public void sendEmailReport(List<AllegatoMail> listaAllegati) throws MessagingException {
  43.  
  44. Map<String, Object> templateContext = new HashMap<String, Object>();
  45. templateContext.put("DATA", DateFormat.getDateInstance(DateFormat.FULL, Locale.ITALY).format(new Date()));
  46.  
  47. sendEmail(mailEventiTo, mailEventiCc, templateFolderReport, templateContext, listaAllegati);
  48. }
  49.  
  50.  
  51. // Send the e-mail attaching to it a list of attachments:
  52. private void sendEmail(String[] toEmail, String[] ccEmail, String templateFolder, Map<String, Object> templateContext, List<AllegatoMail> listaAllegati) throws MessagingException {
  53. protocol = env.getProperty("mail.transport.protocol");
  54. auth = env.getProperty("mail.smtp.auth");
  55. tls = env.getProperty("mail.smtp.starttls.enable");
  56. ssl = env.getProperty("mail.smtp.ssl.enable");
  57. debug = env.getProperty("mail.debug");
  58. this.fromEmail = env.getProperty("mail.smtp.from");
  59. //Assert.hasLength(toEmail);
  60. //Assert.hasLength(fromEmail);
  61. //Assert.hasLength(templateFolder);
  62. //Assert.notNull(templateContext);
  63. templateContext.put("dateTool", new DateTool());
  64. Locale locale = Locale.ITALIAN;
  65. String subjectTemplate = getTemplate(templateFolder, "subject", locale, ".txt");
  66. String htmlBodyTemplate = getTemplate(templateFolder, "body", locale, ".html");
  67. logger.debug(htmlBodyTemplate);
  68. MimeMessage mm = buildMimeMessage(toEmail, ccEmail, fromEmail, templateContext, subjectTemplate, htmlBodyTemplate, listaAllegati);
  69. org.springframework.mail.javamail.JavaMailSenderImpl sender = (org.springframework.mail.javamail.JavaMailSenderImpl) javaMailSender;
  70. sender.setJavaMailProperties(getMailProperties());
  71. javaMailSender.send(mm);
  72. }
  73.  
  74. }
  75.  
  76. public void sendEmailReport(List<AllegatoMail> listaAllegati) throws MessagingException {
  77.  
  78. Map<String, Object> templateContext = new HashMap<String, Object>();
  79. templateContext.put("DATA", DateFormat.getDateInstance(DateFormat.FULL, Locale.ITALY).format(new Date()));
  80.  
  81. sendEmail(mailEventiTo, mailEventiCc, templateFolderReport, templateContext, listaAllegati);
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement