Commit 915e9079b612ac9bd0a4cd2def1c6630ed65b665
1 parent
d2a9a453
Exists in
master
Complemento de novas funcionalidades.
Showing
4 changed files
with
155 additions
and
11 deletions
Show diff stats
src/br/com/model/entity/EnvioEmailSemAutenticacao.java
1 | 1 | package br.com.model.entity; |
2 | 2 | |
3 | -import java.util.List; | |
4 | 3 | import java.util.Properties; |
5 | 4 | |
5 | +import javax.activation.DataHandler; | |
6 | 6 | import javax.mail.Authenticator; |
7 | +import javax.mail.BodyPart; | |
7 | 8 | import javax.mail.Message; |
9 | +import javax.mail.Multipart; | |
8 | 10 | import javax.mail.PasswordAuthentication; |
9 | 11 | import javax.mail.Session; |
10 | 12 | import javax.mail.Transport; |
11 | 13 | import javax.mail.internet.InternetAddress; |
14 | +import javax.mail.internet.MimeBodyPart; | |
12 | 15 | import javax.mail.internet.MimeMessage; |
13 | - | |
14 | -import org.apache.commons.codec.StringEncoder; | |
15 | -import org.apache.commons.io.output.StringBuilderWriter; | |
16 | - | |
17 | -import br.com.model.utilities.StringHelper; | |
16 | +import javax.mail.internet.MimeMultipart; | |
18 | 17 | |
19 | 18 | |
20 | 19 | public class EnvioEmailSemAutenticacao { |
... | ... | @@ -79,6 +78,7 @@ public class EnvioEmailSemAutenticacao { |
79 | 78 | msg.setFrom(new InternetAddress(from)); |
80 | 79 | // Setando o assunto |
81 | 80 | msg.setSubject(subject); |
81 | + | |
82 | 82 | // Setando o conte�do/corpo do email |
83 | 83 | msg.setContent(message, "text/html; charset=utf-8"); |
84 | 84 | |
... | ... | @@ -194,6 +194,111 @@ public class EnvioEmailSemAutenticacao { |
194 | 194 | } |
195 | 195 | return retorno; |
196 | 196 | } |
197 | + | |
198 | + | |
199 | + public String sendMailComAnexo(String from, String to, String subject, | |
200 | + String corpoEmail, String comAutenticacao, String authuser, | |
201 | + String authpass, DataHandler arquivoRelatorio, String nomeArquivoRelatorio, DataHandler arquivoPlano, String nomeArquivoPlano) { | |
202 | + | |
203 | + Properties props = new Properties(); | |
204 | + String retorno = ""; | |
205 | + | |
206 | + props.put("mail.transport.protocol", "smtp"); // define protocolo de | |
207 | + // envio como SMTP | |
208 | + props.put("mail.smtp.starttls.enable", "true"); | |
209 | + props.put("mail.smtp.host", mailSMTPServer); // server SMTP do GMAIL | |
210 | + props.put("mail.smtp.auth", comAutenticacao); // ativa autenticacao | |
211 | + props.put("mail.smtp.user", from); // usuario ou seja, a conta que esta | |
212 | + // enviando o email (tem que ser do | |
213 | + // GMAIL) | |
214 | + props.put("mail.debug", "false"); | |
215 | + props.put("mail.smtp.port", mailSMTPServerPort); // porta | |
216 | + | |
217 | + | |
218 | + // Cria um autenticador que sera usado a seguir | |
219 | + SimpleAuth auth = null; | |
220 | + auth = new SimpleAuth(authuser, authpass); | |
221 | + // Session - objeto que ira realizar a conex�o com o servidor | |
222 | + /* | |
223 | + * Como h� necessidade de autentica��o � criada uma autenticacao que � | |
224 | + * responsavel por solicitar e retornar o usu�rio e senha para | |
225 | + * autentica��o | |
226 | + */ | |
227 | + Session session = Session.getDefaultInstance(props, auth); | |
228 | + session.setDebug(true); // Habilita o LOG das a��es executadas durante o | |
229 | + // envio do email | |
230 | + // Objeto que cont�m a mensagem | |
231 | + Message msg = new MimeMessage(session); | |
232 | + try { | |
233 | + | |
234 | + | |
235 | + // Setando o destinat�rio | |
236 | + | |
237 | + msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to)); | |
238 | + msg.reply(false); | |
239 | + | |
240 | + | |
241 | + // Setando a origem do email | |
242 | + msg.setFrom(new InternetAddress(from)); | |
243 | + // Setando o assunto | |
244 | + msg.setSubject(subject); | |
245 | + | |
246 | + Multipart multipart = new MimeMultipart(); | |
247 | + | |
248 | + //Anexando Arquivo | |
249 | + //FileDataSource fds = new FileDataSource(caminhoArquivo); | |
250 | + MimeBodyPart attachment0 = new MimeBodyPart(); | |
251 | + | |
252 | + attachment0.setDataHandler(arquivoRelatorio); | |
253 | + attachment0.setFileName(nomeArquivoRelatorio); | |
254 | + | |
255 | + multipart.addBodyPart(attachment0); | |
256 | + | |
257 | + | |
258 | + MimeBodyPart attachment1 = new MimeBodyPart(); | |
259 | + | |
260 | + attachment1.setDataHandler(arquivoPlano); | |
261 | + attachment1.setFileName(nomeArquivoPlano); | |
262 | + multipart.addBodyPart(attachment1); | |
263 | + | |
264 | + | |
265 | + | |
266 | + | |
267 | + // Setando o conte�do/corpo do email | |
268 | + MimeBodyPart attachment2 = new MimeBodyPart(); | |
269 | + attachment2.setContent(corpoEmail, "text/html; charset=utf-8"); | |
270 | + multipart.addBodyPart(attachment2); | |
271 | + | |
272 | + msg.setContent(multipart); | |
273 | + | |
274 | + } catch (Exception e) { | |
275 | + retorno = e.getMessage(); | |
276 | + System.out.println(">> Erro: Completar Mensagem"); | |
277 | + e.printStackTrace(); | |
278 | + return retorno; | |
279 | + } | |
280 | + // Objeto encarregado de enviar os dados para o email | |
281 | + Transport tr; | |
282 | + try { | |
283 | + tr = session.getTransport("smtp"); // define smtp para transporte | |
284 | + /* | |
285 | + * 1 - define o servidor smtp 2 - seu nome de usuario do gmail 3 - | |
286 | + * sua senha do gmail | |
287 | + */ | |
288 | + tr.connect(mailSMTPServer, authuser, authpass); | |
289 | + msg.saveChanges(); // don't forget this | |
290 | + // envio da mensagem | |
291 | + tr.send(msg);//(msg, msg.getAllRecipients()); | |
292 | + | |
293 | + tr.close(); | |
294 | + | |
295 | + } catch (Exception e) { | |
296 | + | |
297 | + System.out.println(">> Erro: Envio Mensagem"); | |
298 | + retorno = e.getMessage(); | |
299 | + } | |
300 | + return retorno; | |
301 | +} | |
197 | 302 | |
198 | 303 | } |
199 | 304 | ... | ... |
src/br/com/model/entity/PlanoTrabalho.java
... | ... | @@ -4,7 +4,9 @@ public class PlanoTrabalho { |
4 | 4 | |
5 | 5 | private int idPlanoTrabalho; |
6 | 6 | private byte[] arquivoPlanoTrabalho; |
7 | - private String nomeExtensao; | |
7 | + private String nomeExtensaoPlanoTrabalho; | |
8 | + private byte[] arquivoRelatorioAss; | |
9 | + private String nomeExtensaoRelatorioAss; | |
8 | 10 | private Questionario questionario; |
9 | 11 | |
10 | 12 | public int getIdPlanoTrabalho() { |
... | ... | @@ -20,11 +22,12 @@ public class PlanoTrabalho { |
20 | 22 | public void setArquivoPlanoTrabalho(byte[] arquivoPlanoTrabalho) { |
21 | 23 | this.arquivoPlanoTrabalho = arquivoPlanoTrabalho; |
22 | 24 | } |
23 | - public String getNomeExtensao() { | |
24 | - return nomeExtensao; | |
25 | + | |
26 | + public String getNomeExtensaoPlanoTrabalho() { | |
27 | + return nomeExtensaoPlanoTrabalho; | |
25 | 28 | } |
26 | - public void setNomeExtensao(String nomeExtensao) { | |
27 | - this.nomeExtensao = nomeExtensao; | |
29 | + public void setNomeExtensaoPlanoTrabalho(String nomeExtensaoPlanoTrabalho) { | |
30 | + this.nomeExtensaoPlanoTrabalho = nomeExtensaoPlanoTrabalho; | |
28 | 31 | } |
29 | 32 | public Questionario getQuestionario() { |
30 | 33 | return questionario; |
... | ... | @@ -32,5 +35,17 @@ public class PlanoTrabalho { |
32 | 35 | public void setQuestionario(Questionario questionario) { |
33 | 36 | this.questionario = questionario; |
34 | 37 | } |
38 | + public byte[] getArquivoRelatorioAss() { | |
39 | + return arquivoRelatorioAss; | |
40 | + } | |
41 | + public void setArquivoRelatorioAss(byte[] arquivoRelatorioAss) { | |
42 | + this.arquivoRelatorioAss = arquivoRelatorioAss; | |
43 | + } | |
44 | + public String getNomeExtensaoRelatorioAss() { | |
45 | + return nomeExtensaoRelatorioAss; | |
46 | + } | |
47 | + public void setNomeExtensaoRelatorioAss(String nomeExtensaoRelatorioAss) { | |
48 | + this.nomeExtensaoRelatorioAss = nomeExtensaoRelatorioAss; | |
49 | + } | |
35 | 50 | |
36 | 51 | } | ... | ... |
src/br/com/model/entity/Questionario.java
... | ... | @@ -23,6 +23,7 @@ public class Questionario { |
23 | 23 | private String dtRespostaEmail; |
24 | 24 | private String dataRespostaQuestionario; |
25 | 25 | private boolean planoTrabalhoEnviado; |
26 | + private boolean flagEnviado; | |
26 | 27 | |
27 | 28 | |
28 | 29 | |
... | ... | @@ -50,6 +51,8 @@ public class Questionario { |
50 | 51 | this.idAutorizacaoGeracaoHash = rset.getInt("idAutorizacao"); |
51 | 52 | this.dtRecebimentoEmail = rset.getString("data_recebimento_email"); |
52 | 53 | this.dtRespostaEmail = rset.getString("data_resposta_email"); |
54 | + this.flagEnviado = rset.getBoolean("flag_enviado"); | |
55 | + | |
53 | 56 | |
54 | 57 | } |
55 | 58 | } catch (Exception e) { |
... | ... | @@ -179,6 +182,14 @@ public class Questionario { |
179 | 182 | this.planoTrabalhoEnviado = planoTrabalhoEnviado; |
180 | 183 | } |
181 | 184 | |
185 | + public boolean isFlagEnviado() { | |
186 | + return flagEnviado; | |
187 | + } | |
188 | + | |
189 | + public void setFlagEnviado(boolean flagEnviado) { | |
190 | + this.flagEnviado = flagEnviado; | |
191 | + } | |
192 | + | |
182 | 193 | |
183 | 194 | |
184 | 195 | } | ... | ... |
src/br/com/model/utilities/Email.java
... | ... | @@ -29,6 +29,7 @@ public class Email<InternetAddress> { |
29 | 29 | private String to; |
30 | 30 | private String from; |
31 | 31 | private String copiaEmailTo; |
32 | + private String anexosTo; | |
32 | 33 | |
33 | 34 | private MultiPartEmail email; |
34 | 35 | private EmailAttachment anexo; |
... | ... | @@ -114,6 +115,16 @@ public class Email<InternetAddress> { |
114 | 115 | public void setAnexo(EmailAttachment anexo) { |
115 | 116 | this.anexo = anexo; |
116 | 117 | } |
118 | + | |
119 | + | |
120 | + | |
121 | + public String getAnexosTo() { | |
122 | + return anexosTo; | |
123 | + } | |
124 | + | |
125 | + public void setAnexosTo(String anexosTo) { | |
126 | + this.anexosTo = anexosTo; | |
127 | + } | |
117 | 128 | |
118 | 129 | private void initConf(String path){ |
119 | 130 | ManagerProperties managerProperties = new ManagerProperties(); |
... | ... | @@ -128,6 +139,7 @@ public class Email<InternetAddress> { |
128 | 139 | this.to = prop.getProperty("prop.email.to"); |
129 | 140 | this.from = prop.getProperty("prop.email.from"); |
130 | 141 | this.copiaEmailTo = prop.getProperty("prop.email.copiaEmailTo"); |
142 | + this.anexosTo = prop.getProperty("prop.email.anexosTo"); | |
131 | 143 | |
132 | 144 | } catch (IOException e) { |
133 | 145 | // TODO Auto-generated catch block |
... | ... | @@ -147,6 +159,7 @@ public class Email<InternetAddress> { |
147 | 159 | this.to = to; |
148 | 160 | this.email = new HtmlEmail(); |
149 | 161 | |
162 | + | |
150 | 163 | } |
151 | 164 | |
152 | 165 | /** | ... | ... |