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-87c2c4800839master
parent
7385f14df9
commit
82c294a658
|
@ -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 = {};
|
||||
|
|
Loading…
Reference in New Issue