浏览代码

Versão em PRD

Elemar Deckmann 1 年之前
父节点
当前提交
770269eb37

+ 1 - 0
src/main/java/com/ademicon/controller/EmailController.java

@@ -36,6 +36,7 @@ public class EmailController {
     @Produces(MediaType.APPLICATION_JSON)
     public Response doPost(Email email) throws Exception {
         try {
+            System.out.println("ACESSOU API");
             emailService.sendmail(email);
             return Response.ok().build();
 

+ 30 - 4
src/main/java/com/ademicon/service/EmailService.java

@@ -1,5 +1,6 @@
 package com.ademicon.service;
 
+import java.io.UnsupportedEncodingException;
 import java.util.Base64;
 import java.util.List;
 import java.util.Map;
@@ -7,6 +8,7 @@ import java.util.Properties;
 
 import javax.mail.Message;
 import javax.mail.MessagingException;
+import javax.mail.NoSuchProviderException;
 import javax.mail.PasswordAuthentication;
 import javax.mail.Session;
 import javax.mail.Transport;
@@ -21,7 +23,10 @@ public class EmailService {
     final String username = "prosegnews@conseg.com.br";
     final String password = "Ademicon#2024";
 
-    public void sendmail(Email email) throws Exception {
+    public void sendmail(Email email) throws MessagingException, UnsupportedEncodingException {
+
+        System.out.println("ACESSOU SERVIÇO");
+
         Properties props = new Properties();
         props.setProperty("mail.smtp.starttls.enable", "true");
         props.setProperty("mail.smtp.auth", "true");
@@ -30,6 +35,8 @@ public class EmailService {
         props.setProperty("mail.smtp.port", "587");
         props.setProperty("mail.smtp.ssl.trust", "smtp.office365.com");
 
+        System.out.println("EMAIL DEFINIU PROPRIEDADES");
+
         Session session = Session.getInstance(props,
                 new javax.mail.Authenticator() {
                     protected PasswordAuthentication getPasswordAuthentication() {
@@ -37,8 +44,12 @@ public class EmailService {
                     }
                 });
 
+        System.out.println("EMAIL AUTENTICOU");
+
         Transport transport = session.getTransport();
 
+        System.out.println("EMAIL TRANSPORTE");
+
         try {
 
             Message message = new MimeMessage(session);
@@ -106,18 +117,33 @@ public class EmailService {
             message.setContent(multipart);
 
             // Método para se autenticar ao servidor
+            System.out.println("INICIARA A CONEXÃO");
             transport.connect();
+            System.out.println("FINALIZOU A CONEXÃO");
 
             // Método para enviar a mensagem criada
             System.out.println("Sending");
             transport.sendMessage(message, message.getAllRecipients());
             System.out.println("Done");
 
+        } catch (NoSuchProviderException e) {
+            System.out.println("ERRO NoSuchProviderException");
+            System.out.println(e);
+            e.printStackTrace();
+            throw e;
+
         } catch (MessagingException e) {
-            System.out.println("Fail");
-            System.out.println("ERRO EMAIL ENVIO");
+            System.out.println("ERRO MessagingException");
+            System.out.println(e);
             e.printStackTrace();
-            throw new Exception("Falha ao enviar e-mail de faturamento para " + email.getTo());
+            throw e;
+
+        } catch (UnsupportedEncodingException e) {
+            System.out.println("ERRO UnsupportedEncodingException");
+            System.out.println(e);
+            e.printStackTrace();
+            throw e;
+
         } finally {
             transport.close();
         }

+ 5 - 1
src/main/webapp/WEB-INF/web.xml

@@ -2,7 +2,6 @@
 	xmlns="http://xmlns.jcp.org/xml/ns/javaee"
 	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 	xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd">
-
     <security-constraint>
         <display-name>REST</display-name>
         <web-resource-collection>
@@ -15,6 +14,11 @@
             <role-name>user</role-name>
         </auth-constraint>
     </security-constraint> 
+
+    <login-config>
+        <auth-method>FORM</auth-method>
+        <realm-name>TOTVSTech</realm-name>
+    </login-config>
     <security-role>
         <role-name>totvstech</role-name>
     </security-role>