From 82c294a658cb617e31685b98268a0ea4dffdec2d Mon Sep 17 00:00:00 2001 From: "lucas.taia" Date: Fri, 12 Jul 2019 00:18:40 +0000 Subject: [PATCH] fixes bug#14828 dev:lucas qua: git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@95677 d1611594-4594-4d17-8e1d-87c2c4800839 --- .../ventaboletos/utilerias/SendMail.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/src/com/rjconsultores/ventaboletos/utilerias/SendMail.java b/src/com/rjconsultores/ventaboletos/utilerias/SendMail.java index a6a0dc57a..ad044a5d9 100644 --- a/src/com/rjconsultores/ventaboletos/utilerias/SendMail.java +++ b/src/com/rjconsultores/ventaboletos/utilerias/SendMail.java @@ -13,6 +13,7 @@ import java.util.Properties; import javax.activation.DataHandler; import javax.activation.DataSource; import javax.activation.FileDataSource; +import javax.mail.AuthenticationFailedException; import javax.mail.BodyPart; import javax.mail.Message; import javax.mail.MessagingException; @@ -131,6 +132,62 @@ public class SendMail implements java.io.Serializable { throw new SendFailedException("Ocorreu um erro no envio do email.", e); } } + + public void sendEmail(TypeContentEmail type) throws AuthenticationFailedException, MessagingException, Exception { + String[] to = removeNull(getArrayEnderecoEmail(emailTo)); + String[] bcc = removeNull(getArrayEnderecoEmail(emailToCO)); + + Session session = Session.getInstance(getProperties(), null); + + Message message = new MimeMessage(session); + message.setFrom(new InternetAddress(emailFrom)); + message.setRecipients(Message.RecipientType.TO, getInternetAddress(to)); + message.setRecipients(Message.RecipientType.BCC, getInternetAddress(bcc)); + InternetAddress[] copyAddress = getInternetAddress(new String[emailCopy.size()]); + if (copyAddress.length > 0) { + message.setRecipients(Message.RecipientType.CC, copyAddress); + } + + ((MimeMessage) message).setSubject(subject, ENCODE_UTF_8); + + Multipart multipart = new MimeMultipart(); + multipart.addBodyPart(type == null ? getMimeBodyPart() : getMimeBodyPart(type)); + message.setContent(multipart); + + adicionarAnexos(multipart); + + Transport t = session.getTransport("smtp"); + if (auth) { + t.connect(smtpUser, smtpPassword); + } else { + t.connect(); + + } + t.sendMessage(message, message.getAllRecipients()); + t.close(); + } + + public boolean testConfiguration() throws AuthenticationFailedException, MessagingException, Exception { + boolean result = false; + + Session session = Session.getInstance(getProperties(), null); + + Message message = new MimeMessage(session); + + ((MimeMessage) message).setSubject(subject, ENCODE_UTF_8); + + Transport t = session.getTransport("smtp"); + if (auth) { + t.connect(smtpUser, smtpPassword); + } else { + t.connect(); + + } + t.close(); + result = true; + + return result; + } private String[] getArrayEnderecoEmail(String emailValue) { String[] arrayEmail = {};