Bom dia a todos,
Estou tendo um problema ao enviar email.
Eu uso o commons-email na versão 1.4, como podem ver no meu pom.xml:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
<version>1.4</version>
</dependency>
Estava funcionando normalmente, só que sem nenhuma alteração na parte que envia o email não está funcionando corretamente.
Segue meu metodo de envio de email:
public void sendEmail(Collection<FileAttachment> attachments) {
EmailConfig cfg = new EmailConfig(config);
HtmlEmail email = new HtmlEmail();
email.setSslSmtpPort(cfg.getSMTPPort());
email.setDebug(cfg.getDebug());
email.setStartTLSEnabled(cfg.getTLS());
email.setSSLOnConnect(cfg.getSSL());
email.setHostName(cfg.getHostName());
email.setFrom(cfg.getFrom(), cfg.getTitle());
setCharset(cfg, email);
email.setAuthentication(cfg.getAuthentication(), cfg.getPassword());
email.setSmtpPort(Integer.parseInt(cfg.getSMTPPort()));
addCopy(cfg.getEmailCopy(), email);
email.setHtmlMsg(cfg.getMessage());
//I set attachment here
for (FileAttachment fileAttachment : attachments) {
EmailAttachment attachment = new EmailAttachment();
String tmp = System.getProperty("java.io.tmpdir") + fileAttachment.getName();
File file = new File(tmp);
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file));
out.write(fileAttachment.getByte());
out.close();
attachment.setPath(extractFile(file, getNameAbbreviate()).getAbsolutePath());
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setName(file.getNome());
email.attach(attachment);
}
return email;
}
Quando eu executo o send, eu recebo o email. Só que o email não vem como deveria, abaixo se encontra um exemplo de como eu recebo o email:
------=_Part_2_31318333.1485292342397
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<html><head><meta http-equiv=3D'Content-Type' content=3D'text/html; charset=
=3Diso-8859-1'/></head><body><table width=3D'100%' border=3D'0' cellspacing=
=3D'0' cellpadding=3D'0'><tr><td class=3D'mainbar' align=3D'left' valign=3D'= top'>
Dear client,<br/><br/> The invoice was successfully generated.<br/><br/></td></tr>
</table></body></html>
------=_Part_2_31318333.1485292342397
Content-Type: application/octet-stream; name=doc001.pdf
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=doc001.pdf
Content-Description:
JVBERi0xLjQKJeLjz9MKNiAwIG9iago8PC9UeXBlL1hPYmplY3QvQ29sb3JTcGFjZS9EZXZpY2VS
R0IvU3VidHlwZS9JbWFnZS9CaXRzUGVyQ29tcG9uZW50IDgvV2lkdGggMjAwL0xlbmd0aCA4MjE4
L0hlaWdodCAyMDAvRmlsdGVyL0RDVERlY29kZT4+c3RyZWFtCv/Y/+AAEEpGSUYAAQIAAAEAAQAA
/9sAQwAIBgYHBgUIBwcHCQkICgwUDQwLCwwZEhMPF...
Desde já agradeço a ajuda de todos.