dcsimg
A question about encoding.
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Stefano_Subbacchi
Posted On:   Monday, July 23, 2001 03:55 AM

I have a problem in correctly encoding a textual content in a MimeBodyPart(). I write the following code: MimeBodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText(message, "iso-8859-1"); MimeMultipart multipart = new MimeMultipart(); multipart.addBodyPart(messageBodyPart); mess.setContent(multipart); mess.saveChanges(); mess.writeTo(sock.getOutputStream()); but when I send a message with the implemented SMTP client, the received messages seem still US ASCII 7 bit encoded. Why? How can I resolve the problem? Is it related to a improper use of the method wri   More>>

I have a problem in correctly encoding a textual content in a MimeBodyPart(). I write the following code:




MimeBodyPart messageBodyPart = new MimeBodyPart();

messageBodyPart.setText(message, "iso-8859-1");




MimeMultipart multipart = new MimeMultipart();

multipart.addBodyPart(messageBodyPart);




mess.setContent(multipart);

mess.saveChanges();

mess.writeTo(sock.getOutputStream());






but when I send a message with the implemented SMTP client, the received messages seem still US ASCII 7 bit encoded. Why? How can I resolve the problem? Is it related to a improper use of the method writeTo()?

Thank you for helping me.





Best Regards,




Stefano Subbacchi

Todi (PG) - ITALY







PS: for more clarity, I report the complete code of my method below....







protected void sendData (Socket sock,
String sender,
String rcpt,
String subject,
String message,
String filename)




{

PrintWriter out = null;


MimeUtility mimeTypesHandler = null;


try

{

out = new PrintWriter(sock.getOutputStream());

}


catch(java.io.IOException ee)


{

System.out.println("Catturata eccezione: " + ee.getMessage());

}



Properties props = System.getProperties();

Session session = Session.getInstance(props, null);


// Create a JavaMail Message object

Message mess = new MimeMessage(session);


// Create the message part

MimeBodyPart messageBodyPart = new MimeBodyPart();


try

{

mess.setFrom(new InternetAddress(sender));

mess.addRecipient(Message.RecipientType.TO, new InternetAddress(rcpt));

mess.setSubject(subject);


// Fill the message

messageBodyPart.setText(message, "iso-8859-1");



// Create a Multipart

MimeMultipart multipart = new MimeMultipart();






//
// Add part one
//


multipart.addBodyPart(messageBodyPart);







//
//Part two is attachment
//


// Create second body part

messageBodyPart = new MimeBodyPart();


// Get the attachment

DataSource source = new FileDataSource(filename);


// Set the data handler to the attachment

messageBodyPart.setDataHandler(new DataHandler(source));


// Set the filename

messageBodyPart.setFileName(filename);


// Add part two

multipart.addBodyPart(messageBodyPart);



// Put parts in the message

mess.setContent(multipart);

mess.saveChanges();

mess.writeTo(sock.getOutputStream());


}

catch(javax.mail.MessagingException MEx)


{

System.out.println("Catturata eccezione: " + MEx.getMessage());

}




catch (java.io.IOException IOEx)


{

System.out.println("Catturata eccezione: " + IOEx.getMessage());

}




// end data with .

out.write("
.
");

out.flush();

}.

   <<Less
About | Sitemap | Contact