Olá Pessoal, Como faço para enviar imagens in-line (aquelas imagens que podem ser
usadas em e-mails em formato HTML, em tags IMG por exemplo) em e-mails de forma
a funcionar no Outlook e no Netscape Mail ? Fiz um pequeno código que funciona
somente para Outlook, mas no Netscape a imagem vem faltando (com ícone
quebrado, como se não tivesse imagem). A seguir apresento o código que estou
utilizando : Neste código crio 2 MimeParts, sendo um o código
html (text/html) e outro uma imagem gif (image/gif), coloco os dois em uma
MultiPart e envio. No outlook 2000 vejo a imagem normalmente, como numa página
HTML, mas no Netscape Mail a imagem não vem (vem com ícone de imagem quebrada). import java.util.*; import java.io.*; import javax.mail.*; import javax.mail.internet.*; import javax.activation.*; import java.net.*; import com.own.ByteArrayDataSource; public class InLineEmails { public static void main(String args[]) { InLineEmails that = new InLineEmails(); that.go(); } public void go() { // create some erties and get the default
Session Properties props = System.getProperties();
props.put("mail.smtp.host",
"smtp.tesla.com.br");
Session
ses = Session.getInstance(props,null);
try
{
// create a message
MimeMessage msg = new
MimeMessage(ses);
msg.setFrom(new
InternetAddress("[EMAIL PROTECTED]"));
Address[]
toAddress = InternetAddress.parse("[EMAIL PROTECTED]");
msg.setRecipients(Message.RecipientType.TO,toAddress);
msg.setSubject("Teste de Assunto"); // Reading the HTML to a byte variable File theHTML = new File("C:\\Down\\texto.html"); FileInputStream fisHTML = new
FileInputStream(theHTML); byte[] fileInBytesHTML = new
byte[((int)(theHTML.length()))]; fisHTML.read(fileInBytesHTML); fisHTML.close();
MimeBodyPart mbp2 =
new MimeBodyPart(); mbp2.addHeaderLine("Content-Type:
text/html; charset=us-ascii"); mbp2.addHeaderLine("Content-Transfer-Encoding:
7bit"); mbp2.setDataHandler(new DataHandler(new
ByteArrayDataSource(fileInBytesHTML, "text/html"))); // Reading the Image to a byte variable File theFile = new File("C:\\Down\\Teste.gif"); FileInputStream fis = new
FileInputStream(theFile); byte[] fileInBytes = new
byte[((int)(theFile.length()))]; fis.read(fileInBytes); fis.close();
// create and fill the
image message part
MimeBodyPart mbpImage
= new MimeBodyPart();
mbpImage.addHeaderLine("Content-Type:
image/gif");
mbpImage.addHeaderLine("Content-ID:
<[EMAIL PROTECTED]>");
mbpImage.addHeaderLine("Content-Transfer-Encoding:
base64");
mbpImage.addHeaderLine("Content-Disposition:
inline; filename=\"C:\\Down\\Teste.gif\"");
mbpImage.setDisposition(Part.INLINE);
mbpImage.setDataHandler(new
DataHandler(new ByteArrayDataSource(fileInBytes, "image/gif")));
// create the
Multipart and its parts to it
Multipart mp = new
MimeMultipart();
//mp.addBodyPart(mbp1);
mp.addBodyPart(mbp2);
mp.addBodyPart(mbpImage);
// add the Multipart
to the message
msg.setContent(mp);
// set the Date:
header
msg.setSentDate(new
Date());
// send the message
Transport.send(msg); }catch (Exception ex) { ex.printStackTrace();
} } } No arquivo texto.html tenho um código HTML que será lido e incluído na
mensagem : <html> Teste de e-mail <br> <img
SRC="cid:[EMAIL PROTECTED]" height=91
width=253> </html> Desde já agradeço, Sergio
Stateri Jr Tesla Tecnologia Sao Paulo (SP) |
- RES: [java-list] Imagens In-line no JavaMail 1.1.3 Sergio Stateri Jr
- RES: [java-list] Imagens In-line no JavaMail 1.1.3 Sergio Stateri Jr