Home arrow static arrow Java Programming [Archive] - Problem with mail
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Problem with mail
This topic has 1 reply on 1 page.

Posts:250
Registered: 10/30/01
Problem with mail  
Jul 27, 2004 12:59 AM



 

Hi All

I need to create a mail that will have a body with text and html with an embeded image, and will include a txt file as attachment.

Then I did:

1 - create body

Message message = new MimeMessage(session); // Fill its headersmessage.setFrom(new InternetAddress("xxxx@xxx.com"));message.addRecipient(Message.RecipientType.TO, new InternetAddress("zzzz@zzzz.com"));message.setSubject("Prueba de test app");


2 - create body parts as alternative

MimeBodyPart plainPart = new MimeBodyPart();plainPart.setText(contenido, "iso-8859-1"); MimeBodyPart htmlPart = new MimeBodyPart();String htmlText = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"><HTML><HEAD>" +		"<META http-equiv=Content-Type content=\"text/html; charset=iso-8859-1\"></HEAD>" +		"<body><pre>" + contenido + "</pre><br/><img src=\"cid:logotroex\"></body></html>"; htmlPart.setContent(htmlText, "text/html;charset=\"iso-8859-1\""); Multipart alt = new MimeMultipart("alternative");alt.addBodyPart(plainPart);alt.addBodyPart(htmlPart);


3 - Then create a mixed part to add image and attach

Multipart mixed = new MimeMultipart("mixed");MimeBodyPart wrap = new MimeBodyPart();wrap.setContent(alt);    // HERE'S THE KEYmixed.addBodyPart(wrap);  // Create part for the imageMimeBodyPart messageBodyPart = new MimeBodyPart(); // Fetch the image and associate to partDataSource fds = new FileDataSource(new File("troex.jpg"));messageBodyPart.setDataHandler(new DataHandler(fds)); // Add a header to connect to the HTMLmessageBodyPart.setHeader("Content-ID","<logotroex>"); mixed.addBodyPart(messageBodyPart); // Add AttachmessageBodyPart = new MimeBodyPart();DataSource source = new FileDataSource(new File("A000120102004.txt"));messageBodyPart.setDataHandler(new DataHandler(source));messageBodyPart.setFileName(source.getName());messageBodyPart.setHeader("Content-Transfer-Encoding", "base64");messageBodyPart.setDisposition("attachment"); mixed.addBodyPart(messageBodyPart);  message.setContent(mixed); // Send messageTransport.send(message);


But mails are received with problems in various mails servers (Merak, Exchange).

I've analized mail received by clients and I discovered that attachs are not correctly separated. For example, in a correct mail I would see:

------=_Part_1_26204548.1090881584458
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-ID: <logosegex>

encoded image here

------=_Part_1_26204548.1090881584458--

------=_Part_1_26204548.1090881584458
Content-Type: text/plain; name=A000120102004.txt; charset=Cp1252
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=A000120102004.txt

encoded attach here

------=_Part_1_26204548.1090881584458--


But my routine generate this

------=_Part_1_26204548.1090881584458
Content-Type: image/jpeg
Content-Transfer-Encoding: base64
Content-ID: <logosegex>

encoded image here

------=_Part_1_26204548.1090881584458
Content-Type: text/plain; name=A000120102004.txt; charset=Cp1252
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=A000120102004.txt

encoded attach here

------=_Part_1_26204548.1090881584458--

Then, I see the line ------=_Part_1_26204548.1090881584458-- that close the first part before the attach is absent.

Then my quesiton is: how could I make my routine to work correctly ?

Thanks in advance

<jl>

 

Posts:319
Registered: 11/8/00
Re: Problem with mail  
Jul 27, 2004 1:47 AM (reply 1 of 1)



 
Please do not cross post it cuts down the effectiveness of the fourms

http://forum.java.sun.com/thread.jsp?forum=43&thread=541513
http://forum.java.sun.com/thread.jsp?forum=54&thread=541512
http://forum.java.sun.com/thread.jsp?forum=31&thread=541515
 
This topic has 1 reply on 1 page.