Resolvido!
Vlw a dica Henrique.
Em 23 de julho de 2014 15:28, Henrique Melo <henrique1985@gmail.com> escreveu:
Vou colar um codigo aquiQlqr bronca eu explico..public static boolean enviarEmail(List<String> emails, String localArquivo,String mensagemEmail, String tituloEmail, String remetente)throws Exception {Boolean retorno = false;String from = remetente;String host = "192.168.1.3";String filename = localArquivo;String msgText1 = mensagemEmail;String subject = tituloEmail;// cria algumas propriedades e obtem uma sessao padraoProperties props = System.getProperties();props.put("mail.smtp.host", host);props.put("port", "25");Session session = Session.getInstance(props, null);// cria a mensagemMimeMessage msg = new MimeMessage(session);msg.setFrom(new InternetAddress(from));// DestinatariosInteger aux = emails.size();InternetAddress[] address = new InternetAddress[aux];aux = 0;for (String email : emails) {address[aux] = new InternetAddress(email.trim());aux++;}// InternetAddress[] address = { new InternetAddress(to) };msg.setRecipients(Message.RecipientType.TO, (address));msg.setSubject(subject);// Testemsg.setHeader("Disposition-Notification-To", from);msg.setHeader("Return-Receipt-To", from);msg.setHeader("X-Confirm-Reading-To", from);// cria a primeira parte da mensagemMimeBodyPart mbp1 = new MimeBodyPart();mbp1.setContent(msgText1, "text/html");// cria a segunda parte da mensageMimeBodyPart mbp2 = new MimeBodyPart();// anexa o arquivo na mensagemFileDataSource fds = new FileDataSource(filename);mbp2.setDataHandler(new DataHandler(fds));mbp2.setFileName(fds.getName());// cria a MultipartMultipart mp = new MimeMultipart();mp.addBodyPart(mbp1);mp.addBodyPart(mbp2);// adiciona a Multipart na mensagemmsg.setContent(mp);// configura a data: cabecalhomsg.setSentDate(new Date());// envia a mensagemTransport.send(msg);return retorno;}--Em 23 de julho de 2014 14:06, Felipe Aron <felipearon@gmail.com> escreveu:
--Fala galera,Estou tentando anexar um arquivo TXT usando o Javamail, porém o conteúdo do arquivo está sendo mostrado diretamente no corpo do email e não como arquivo anexado.
Meu código para anexar os arquivos:public void addAttachment(String filename) throws Exception {DataSource file = new FileDataSource(filename);BodyPart attachment = new MimeBodyPart();attachment.setDataHandler(new DataHandler(file));attachment.setFileName(filename);multipart.addBodyPart(attachment);}Como fazer para anexar o arquivo TXT e não incorporar o conteúdo no corpo do e-mail?--Programador
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--Henrique Nogueira de Melo
Analista e Arquiteto de Software
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Programador
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.






0 comentários:
Postar um comentário