Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <p>Ciao,
- <br />
- in allegato il report dei dati mutui BEI inviati in data ${DATA}.
- <br/><br/>
- </p>
- @Service("emailService")
- @PropertySource("file:///${jboss.modules.dir}/system/layers/base/it/myCompany/projects/myproject/main/myPropertiesFile.properties")
- public class EmailService {
- // TEST
- private static final String[] mailEventiTo = {"test1@gmail.com","test2@gmail.com", "test3@gmail.com"};
- private static final String[] mailEventiCc = {"test1@gmail.com","test2@gmail.com", "test3@gmail.com"};
- private static final String[] mailEccezioneTo = {"test1@gmail.com","test2@gmail.com"};
- @Autowired
- protected JavaMailSender javaMailSender;
- @Autowired
- protected VelocityEngine velocityEngine;
- @Autowired
- private Environment env;
- private String protocol;
- private String auth;
- private String tls;
- private String ssl;
- private String debug;
- private String fromEmail;
- private final String templateFolderReport = "mail/reportBatch";
- private final String templateFolderEccezione = "mail/eccezioni";
- ..........................................................................
- ..........................................................................
- SOME UTILITY METHODS
- ..........................................................................
- ..........................................................................
- public void sendEmailReport(List<AllegatoMail> listaAllegati) throws MessagingException {
- Map<String, Object> templateContext = new HashMap<String, Object>();
- templateContext.put("DATA", DateFormat.getDateInstance(DateFormat.FULL, Locale.ITALY).format(new Date()));
- sendEmail(mailEventiTo, mailEventiCc, templateFolderReport, templateContext, listaAllegati);
- }
- // Send the e-mail attaching to it a list of attachments:
- private void sendEmail(String[] toEmail, String[] ccEmail, String templateFolder, Map<String, Object> templateContext, List<AllegatoMail> listaAllegati) throws MessagingException {
- protocol = env.getProperty("mail.transport.protocol");
- auth = env.getProperty("mail.smtp.auth");
- tls = env.getProperty("mail.smtp.starttls.enable");
- ssl = env.getProperty("mail.smtp.ssl.enable");
- debug = env.getProperty("mail.debug");
- this.fromEmail = env.getProperty("mail.smtp.from");
- //Assert.hasLength(toEmail);
- //Assert.hasLength(fromEmail);
- //Assert.hasLength(templateFolder);
- //Assert.notNull(templateContext);
- templateContext.put("dateTool", new DateTool());
- Locale locale = Locale.ITALIAN;
- String subjectTemplate = getTemplate(templateFolder, "subject", locale, ".txt");
- String htmlBodyTemplate = getTemplate(templateFolder, "body", locale, ".html");
- logger.debug(htmlBodyTemplate);
- MimeMessage mm = buildMimeMessage(toEmail, ccEmail, fromEmail, templateContext, subjectTemplate, htmlBodyTemplate, listaAllegati);
- org.springframework.mail.javamail.JavaMailSenderImpl sender = (org.springframework.mail.javamail.JavaMailSenderImpl) javaMailSender;
- sender.setJavaMailProperties(getMailProperties());
- javaMailSender.send(mm);
- }
- }
- public void sendEmailReport(List<AllegatoMail> listaAllegati) throws MessagingException {
- Map<String, Object> templateContext = new HashMap<String, Object>();
- templateContext.put("DATA", DateFormat.getDateInstance(DateFormat.FULL, Locale.ITALY).format(new Date()));
- sendEmail(mailEventiTo, mailEventiCc, templateFolderReport, templateContext, listaAllegati);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement