Amigos,
Tenho a classe abaixo que envia email com anexo.
O que eu preciso e não estou conseguindo é enviar esse email com cópia.
Me ajude?
Obrigado,
Marques
public class EmailEnvia extends Authenticator {
public void envia(String emailTo, String assunto, String textoEmail, String arquivoToSend)
throws FitDAOException, AddressException, MessagingException {
String emailFrom = Constants.EMAIL;
String password = Constants.EMAIL_SENHA;
String servidor = Constants.HOST_MAIL;
Properties props = new Properties();
props.put("mail.smtp.host", servidor);
Session session = Session.getDefaultInstance(props, new EmailAutentica(emailFrom, password));
Message message = new MimeMessage(session);
try {
// Message from
InternetAddress from = new InternetAddress(emailFrom);
message.setFrom(from);
// Message to
InternetAddress to = new InternetAddress(emailTo);
message.addRecipient(Message.RecipientType.TO, to);
message.setSubject(assunto);
MimeMultipart mpRoot = new MimeMultipart("mixed");
MimeMultipart mpContent = new MimeMultipart("alternative");
MimeBodyPart contentPartRoot = new MimeBodyPart();
contentPartRoot.setContent(mpContent);
mpRoot.addBodyPart(contentPartRoot);
//Send text
MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setText(textoEmail);
mpContent.addBodyPart(mbp1);
/*Send html
MimeBodyPart mbp2 = new MimeBodyPart();
mbp2.setContent("<P> Teste de envio HTML </P>", "text/html");
mpContent.addBodyPart(mbp2);*/
//Send attachment
if (arquivoToSend != null && !arquivoToSend.equals("")) {
MimeBodyPart mbp3 = new MimeBodyPart();
FileDataSource fds = new FileDataSource(arquivoToSend);
mbp3.setDisposition(Part.ATTACHMENT);
mbp3.setDataHandler(new DataHandler(fds));
mbp3.setFileName(fds.getName());
mpRoot.addBodyPart(mbp3);
}
message.setContent(mpRoot);
message.saveChanges();
Transport.send(message);
} catch (AddressException ae) {
ae.printStackTrace();
throw new FitDAOException(ae.getMessage());
} catch (MessagingException me) {
me.printStackTrace();
throw new FitDAOException(me.getMessage());
}
}
}