Commit a0eea91849e4696bb7c36415db4f0c81fc481d4d
Exists in
master
Merge branch 'master' of https://softwarepublico.gov.br:443/gitlab/relatoriocirc…
…unstanciado/relatoriocircunstanciado.git
Showing
6 changed files
with
53 additions
and
15 deletions
Show diff stats
WebContent/WEB-INF/intervaloRespostaFormulario.properties
0 → 100644
WebContent/WEB-INF/jsp/questionario/questionario.jsp
@@ -19,10 +19,6 @@ | @@ -19,10 +19,6 @@ | ||
19 | <input type="text" id="noOrgao" name="noOrgao"><br><br> | 19 | <input type="text" id="noOrgao" name="noOrgao"><br><br> |
20 | <label for="emailDestinoOrgao">Email: </label> | 20 | <label for="emailDestinoOrgao">Email: </label> |
21 | <input type="text" id="emailDestinoOrgao" name="emailDestinoOrgao"><br><br> | 21 | <input type="text" id="emailDestinoOrgao" name="emailDestinoOrgao"><br><br> |
22 | -<label for="dtInicioQuestionario">Início: </label> | ||
23 | -<input type="date" id="dtInicioQuestionario" name="dtInicioQuestionario"><br><br> | ||
24 | -<label for="dtFimQuestionario">Fim: </label> | ||
25 | -<input type="date" id="dtFimQuestionario" name="dtFimQuestionario"><br><br> | ||
26 | <label for="file">Arquivo: </label> | 22 | <label for="file">Arquivo: </label> |
27 | <input type="file" id="file" name="file"><br><br> | 23 | <input type="file" id="file" name="file"><br><br> |
28 | <input type="submit" value="Salvar"> | 24 | <input type="submit" value="Salvar"> |
WebContent/WEB-INF/mail.properties
@@ -6,4 +6,5 @@ prop.email.authuser = "" | @@ -6,4 +6,5 @@ prop.email.authuser = "" | ||
6 | prop.email.authpass = "" | 6 | prop.email.authpass = "" |
7 | prop.email.auth = false | 7 | prop.email.auth = false |
8 | prop.email.to = "" | 8 | prop.email.to = "" |
9 | -prop.email.from = govbr@planejamento.gov.br | ||
10 | \ No newline at end of file | 9 | \ No newline at end of file |
10 | +prop.email.from = govbr@planejamento.gov.br | ||
11 | +prop.email.copiaEmailTo = govbr@planejamento.gov.br | ||
11 | \ No newline at end of file | 12 | \ No newline at end of file |
src/br/com/controller/QuestionarioController.java
1 | package br.com.controller; | 1 | package br.com.controller; |
2 | 2 | ||
3 | import java.io.BufferedReader; | 3 | import java.io.BufferedReader; |
4 | +import java.io.IOException; | ||
4 | import java.io.InputStreamReader; | 5 | import java.io.InputStreamReader; |
6 | +import java.util.Properties; | ||
5 | 7 | ||
8 | +import javax.mail.Address; | ||
6 | import javax.servlet.ServletContext; | 9 | import javax.servlet.ServletContext; |
7 | 10 | ||
8 | import br.com.model.utilities.Email; | 11 | import br.com.model.utilities.Email; |
12 | +import br.com.model.utilities.ManagerProperties; | ||
9 | import br.com.model.utilities.StringHelper; | 13 | import br.com.model.utilities.StringHelper; |
10 | import br.com.caelum.vraptor.Path; | 14 | import br.com.caelum.vraptor.Path; |
11 | import br.com.caelum.vraptor.Resource; | 15 | import br.com.caelum.vraptor.Resource; |
@@ -40,14 +44,29 @@ public class QuestionarioController { | @@ -40,14 +44,29 @@ public class QuestionarioController { | ||
40 | } | 44 | } |
41 | 45 | ||
42 | @Path("/salvar-questionario") | 46 | @Path("/salvar-questionario") |
43 | - public void questionarioSalvar(String emailDestinoOrgao, UploadedFile file, | ||
44 | - String dtInicioQuestionario, String dtFimQuestionario, String noOrgao) { | 47 | + public void questionarioSalvar(String emailDestinoOrgao, UploadedFile file, String noOrgao) { |
45 | 48 | ||
46 | String codigoHash = noOrgao + DateUtil.dataHoraAtual().toString().replace("/", "").replace(" ", "").replace(":", ""); | 49 | String codigoHash = noOrgao + DateUtil.dataHoraAtual().toString().replace("/", "").replace(" ", "").replace(":", ""); |
47 | 50 | ||
48 | Questionario questionario = new Questionario(); | 51 | Questionario questionario = new Questionario(); |
49 | // BufferedReader reader = new BufferedReader(new InputStreamReader(file.getFile())); | 52 | // BufferedReader reader = new BufferedReader(new InputStreamReader(file.getFile())); |
50 | 53 | ||
54 | + ManagerProperties managerProperties = new ManagerProperties(); | ||
55 | + | ||
56 | + String dtInicioQuestionario = ""; | ||
57 | + String dtFimQuestionario = ""; | ||
58 | + | ||
59 | + try { | ||
60 | + Properties prop = managerProperties.getProp(this.application.getRealPath("") + "/WEB-INF/intervaloRespostaFormulario.properties"); | ||
61 | + | ||
62 | + dtInicioQuestionario = prop.getProperty("dataInicio"); | ||
63 | + dtFimQuestionario = prop.getProperty("dataFim"); | ||
64 | + | ||
65 | + } catch (IOException e) { | ||
66 | + // TODO Auto-generated catch block | ||
67 | + e.printStackTrace(); | ||
68 | + } | ||
69 | + | ||
51 | questionario.setDtInicioQuestionario(dtInicioQuestionario); | 70 | questionario.setDtInicioQuestionario(dtInicioQuestionario); |
52 | questionario.setDtFimQuestionario(dtFimQuestionario); | 71 | questionario.setDtFimQuestionario(dtFimQuestionario); |
53 | questionario.setEmailDestinoOrgao(emailDestinoOrgao); | 72 | questionario.setEmailDestinoOrgao(emailDestinoOrgao); |
@@ -85,12 +104,13 @@ public class QuestionarioController { | @@ -85,12 +104,13 @@ public class QuestionarioController { | ||
85 | 104 | ||
86 | EnvioEmailSemAutenticacao envioEmailSemAutenticacao = | 105 | EnvioEmailSemAutenticacao envioEmailSemAutenticacao = |
87 | new EnvioEmailSemAutenticacao(email.getHost(), Integer.toString(email.getPort())); | 106 | new EnvioEmailSemAutenticacao(email.getHost(), Integer.toString(email.getPort())); |
88 | - | 107 | + |
108 | + | ||
89 | respSendEmail = | 109 | respSendEmail = |
90 | envioEmailSemAutenticacao.sendMail(email.getFrom(), contato.getEmail(), | 110 | envioEmailSemAutenticacao.sendMail(email.getFrom(), contato.getEmail(), |
91 | StringHelper.convertFromUTF8(contato.getAssunto()), | 111 | StringHelper.convertFromUTF8(contato.getAssunto()), |
92 | StringHelper.convertFromUTF8(contato.getMensagem()), email.getAuth(), | 112 | StringHelper.convertFromUTF8(contato.getMensagem()), email.getAuth(), |
93 | - email.getAuthUser(), email.getAuthPass()); | 113 | + email.getAuthUser(), email.getAuthPass(), email.getCopiaEmailTo()); |
94 | 114 | ||
95 | 115 | ||
96 | /* | 116 | /* |
src/br/com/model/entity/EnvioEmailSemAutenticacao.java
@@ -31,7 +31,8 @@ public class EnvioEmailSemAutenticacao { | @@ -31,7 +31,8 @@ public class EnvioEmailSemAutenticacao { | ||
31 | 31 | ||
32 | public String sendMail(String from, String to, String subject, | 32 | public String sendMail(String from, String to, String subject, |
33 | String message, String comAutenticacao, String authuser, | 33 | String message, String comAutenticacao, String authuser, |
34 | - String authpass) { | 34 | + String authpass, String copiaEmailTo) { |
35 | + | ||
35 | Properties props = new Properties(); | 36 | Properties props = new Properties(); |
36 | String retorno = ""; | 37 | String retorno = ""; |
37 | 38 | ||
@@ -45,6 +46,7 @@ public class EnvioEmailSemAutenticacao { | @@ -45,6 +46,7 @@ public class EnvioEmailSemAutenticacao { | ||
45 | // GMAIL) | 46 | // GMAIL) |
46 | props.put("mail.debug", "false"); | 47 | props.put("mail.debug", "false"); |
47 | props.put("mail.smtp.port", mailSMTPServerPort); // porta | 48 | props.put("mail.smtp.port", mailSMTPServerPort); // porta |
49 | + | ||
48 | 50 | ||
49 | // Cria um autenticador que sera usado a seguir | 51 | // Cria um autenticador que sera usado a seguir |
50 | SimpleAuth auth = null; | 52 | SimpleAuth auth = null; |
@@ -61,14 +63,21 @@ public class EnvioEmailSemAutenticacao { | @@ -61,14 +63,21 @@ public class EnvioEmailSemAutenticacao { | ||
61 | // Objeto que cont�m a mensagem | 63 | // Objeto que cont�m a mensagem |
62 | Message msg = new MimeMessage(session); | 64 | Message msg = new MimeMessage(session); |
63 | try { | 65 | try { |
66 | + | ||
67 | + | ||
64 | // Setando o destinat�rio | 68 | // Setando o destinat�rio |
65 | msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to)); | 69 | msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to)); |
70 | + msg.setReplyTo(new javax.mail.Address[] | ||
71 | + { | ||
72 | + new javax.mail.internet.InternetAddress(copiaEmailTo) | ||
73 | + }); | ||
74 | + | ||
66 | // Setando a origem do email | 75 | // Setando a origem do email |
67 | msg.setFrom(new InternetAddress(from)); | 76 | msg.setFrom(new InternetAddress(from)); |
68 | // Setando o assunto | 77 | // Setando o assunto |
69 | msg.setSubject(subject); | 78 | msg.setSubject(subject); |
70 | // Setando o conte�do/corpo do email | 79 | // Setando o conte�do/corpo do email |
71 | - msg.setContent(message, "text/html; charset=utf-8"); | 80 | + msg.setContent(message, "text/html; charset=utf-8"); |
72 | 81 | ||
73 | } catch (Exception e) { | 82 | } catch (Exception e) { |
74 | retorno = e.getMessage(); | 83 | retorno = e.getMessage(); |
src/br/com/model/utilities/Email.java
@@ -2,9 +2,13 @@ package br.com.model.utilities; | @@ -2,9 +2,13 @@ package br.com.model.utilities; | ||
2 | 2 | ||
3 | import java.io.IOException; | 3 | import java.io.IOException; |
4 | import java.net.MalformedURLException; | 4 | import java.net.MalformedURLException; |
5 | +import java.util.Collection; | ||
5 | import java.util.Date; | 6 | import java.util.Date; |
7 | +import java.util.List; | ||
6 | import java.util.Properties; | 8 | import java.util.Properties; |
7 | 9 | ||
10 | +import javax.mail.Address; | ||
11 | + | ||
8 | import lombok.AccessLevel; | 12 | import lombok.AccessLevel; |
9 | import lombok.Getter; | 13 | import lombok.Getter; |
10 | import net.htmlparser.jericho.Source; | 14 | import net.htmlparser.jericho.Source; |
@@ -17,8 +21,9 @@ import org.apache.commons.mail.MultiPartEmail; | @@ -17,8 +21,9 @@ import org.apache.commons.mail.MultiPartEmail; | ||
17 | 21 | ||
18 | /** | 22 | /** |
19 | * @category utilities | 23 | * @category utilities |
20 | - * @version 1.0*/ | ||
21 | -public class Email { | 24 | + * @version 1.0 |
25 | + * @param <InternetAddress>*/ | ||
26 | +public class Email<InternetAddress> { | ||
22 | 27 | ||
23 | @Getter private String authUser; | 28 | @Getter private String authUser; |
24 | @Getter private String authPass; | 29 | @Getter private String authPass; |
@@ -27,12 +32,14 @@ public class Email { | @@ -27,12 +32,14 @@ public class Email { | ||
27 | @Getter private int port; | 32 | @Getter private int port; |
28 | @Getter private String to; | 33 | @Getter private String to; |
29 | @Getter private String from; | 34 | @Getter private String from; |
35 | + @Getter private String copiaEmailTo; | ||
30 | 36 | ||
31 | private MultiPartEmail email; | 37 | private MultiPartEmail email; |
32 | private EmailAttachment anexo; | 38 | private EmailAttachment anexo; |
33 | 39 | ||
34 | 40 | ||
35 | - private void initConf(String path){ | 41 | + @SuppressWarnings("unchecked") |
42 | + private void initConf(String path){ | ||
36 | ManagerProperties managerProperties = new ManagerProperties(); | 43 | ManagerProperties managerProperties = new ManagerProperties(); |
37 | try { | 44 | try { |
38 | Properties prop = managerProperties.getProp(path); | 45 | Properties prop = managerProperties.getProp(path); |
@@ -44,6 +51,7 @@ public class Email { | @@ -44,6 +51,7 @@ public class Email { | ||
44 | this.auth = prop.getProperty("prop.email.auth"); | 51 | this.auth = prop.getProperty("prop.email.auth"); |
45 | this.to = prop.getProperty("prop.email.to"); | 52 | this.to = prop.getProperty("prop.email.to"); |
46 | this.from = prop.getProperty("prop.email.from"); | 53 | this.from = prop.getProperty("prop.email.from"); |
54 | + this.copiaEmailTo = prop.getProperty("prop.email.copiaEmailTo"); | ||
47 | 55 | ||
48 | } catch (IOException e) { | 56 | } catch (IOException e) { |
49 | // TODO Auto-generated catch block | 57 | // TODO Auto-generated catch block |
@@ -77,12 +85,14 @@ public class Email { | @@ -77,12 +85,14 @@ public class Email { | ||
77 | * @throws EmailException | 85 | * @throws EmailException |
78 | * @throws MalformedURLException | 86 | * @throws MalformedURLException |
79 | * @return String*/ | 87 | * @return String*/ |
80 | - public String sendEmail2( String nomeDestinatario, String emailDestinatario, String nomeRemetente, String emailRemetente, String assunto, String mensagem, boolean isHtml) throws EmailException { | 88 | + @SuppressWarnings("unchecked") |
89 | + public String sendEmail( String nomeDestinatario, String emailDestinatario, String nomeRemetente, String emailRemetente, String assunto, String mensagem, boolean isHtml, List<InternetAddress> copiaEmailTo) throws EmailException { | ||
81 | 90 | ||
82 | this.email.setHostName(this.host); // o servidor SMTP para envio do e-mail | 91 | this.email.setHostName(this.host); // o servidor SMTP para envio do e-mail |
83 | this.email.addTo(emailDestinatario, nomeDestinatario); //destinat�rio | 92 | this.email.addTo(emailDestinatario, nomeDestinatario); //destinat�rio |
84 | this.email.setFrom(emailRemetente, emailRemetente+", "); // remetente | 93 | this.email.setFrom(emailRemetente, emailRemetente+", "); // remetente |
85 | this.email.setSubject(assunto); // assunto do e-mail | 94 | this.email.setSubject(assunto); // assunto do e-mail |
95 | + this.email.setCc((Collection<javax.mail.internet.InternetAddress>) copiaEmailTo); | ||
86 | 96 | ||
87 | if(isHtml) | 97 | if(isHtml) |
88 | this.email.setContent("<p>Ol�, <b>"+nomeRemetente+"</b> enviou a seguinte mensagem:</p> \n "+mensagem, "text/html"); | 98 | this.email.setContent("<p>Ol�, <b>"+nomeRemetente+"</b> enviou a seguinte mensagem:</p> \n "+mensagem, "text/html"); |