|
@@ -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();
|
|
|
}
|