dcsimg
Messages with HTML body and attachments not well formated with Netscape Messenger...
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Wednesday, July 24, 2002 09:58 AM

I use the code above to send messages with the body HTML formatted and I also attach some files. It works fine with Microsoft's mail clients, but when I try to read with Netscape Messenger I only read the plain text, not the HTML formated. Please help me, I'm getting mad!!! thanx public void enviarMissatgeMultiPart() throws Exception{ Session s = Session.getInstance(props, null); MimeMessage message = new MimeMessage(s); StringBuffer destinatarisString = new StringBuffer(""); try { if(from != null && from.length() > 0){ InternetAddress[] addressFrom = InternetAddress.parse(from); message.setReplyTo(addressFrom);    More>>

I use the code above to send messages with the body HTML formatted and I also attach some files.

It works fine with Microsoft's mail clients, but when I try to read with Netscape Messenger I only read the plain text, not the HTML formated.

Please help me, I'm getting mad!!!

thanx

			
public void enviarMissatgeMultiPart() throws Exception{
Session s = Session.getInstance(props, null);
MimeMessage message = new MimeMessage(s);
StringBuffer destinatarisString = new StringBuffer("");

try {
if(from != null && from.length() > 0){
InternetAddress[] addressFrom = InternetAddress.parse(from);
message.setReplyTo(addressFrom);
message.setFrom(addressFrom[0]);
}

if(this.toAddress != null && this.toAddress.length >0){
message.addRecipients(Message.RecipientType.TO, this.toAddress);
destinatarisString.append("; TO: ");
for(int i = 0; i < this.toAddress.length; i++)
destinatarisString.append(this.toAddress[i].toString() + ", ");
}

if(this.ccAddress != null && this.ccAddress.length >0){
message.addRecipients(Message.RecipientType.CC, this.ccAddress);
destinatarisString.append("; CC: ");
for(int i = 0; i < this.ccAddress.length; i++)
destinatarisString.append(this.ccAddress[i].toString() + ", ");
}

if (importancia != null && importancia.equals(IMPORTANCIA_ALTA)){
message.setHeader("X-Priority", "1");
message.setHeader("Importance", "high");
}
else if (importancia != null && importancia.equals(IMPORTANCIA_BAIXA)){
message.setHeader("Importance", "low");
message.setHeader("X-Priority", "5");
}
else{
message.removeHeader("X-Priority");
message.removeHeader("Importance");
}

message.setSubject(subject,"iso-8859-1");

// Create and fill the second message part with the HTML code
MimeBodyPart mbpa2 = new MimeBodyPart();
mbpa2.setText(missatge,"iso-8859-1");
mbpa2.addHeaderLine("Content-Type:text/plain; charset="iso-8859-1"");
mbpa2.addHeaderLine("Content-Transfer-Encoding: 8bit");

MimeBodyPart mbpa3 = new MimeBodyPart();
mbpa3.setText(com.nexe.utils.Utils.replace(missatge,'
',"
"),"iso-8859-1");
mbpa3.addHeader("Content-Type","iso-8859-1");
mbpa3.addHeaderLine("Content-Type:text/html; charset="iso-8859-1"");
mbpa3.addHeaderLine("Content-Transfer-Encoding: quoted-printable");

Multipart mp = new MimeMultipart("mixed");
Multipart mp2 = new MimeMultipart("alternative");

mp2.addBodyPart(mbpa2);
mp2.addBodyPart(mbpa3);

MimeBodyPart mbp1 = new MimeBodyPart();
mbp1.setContent(mp2);
mp.addBodyPart(mbp1);



if((fitxersAdjunts != null) && (fitxersAdjunts.size() > 0)){
for (int i=0; i < fitxersAdjunts.size(); i++) {
File fitxer = (File)fitxersAdjunts.elementAt(i);
MimeBodyPart mbp;
if (fitxer.isFile()) {
mbp = new MimeBodyPart();
DataSource source = new FileDataSource(fitxer);
mbp.setDataHandler(new DataHandler(source));
mbp.setFileName(fitxer.getName());
mp.addBodyPart(mbp);
}
}
}

message.setContent(mp);
message.setSentDate(new java.util.Date());

Transport.send(message);
Debugger.write(destinatarisString.toString(),
Debugger.INFO,
new File(getDirectoriLogs(),nomFitxer));
}
catch (MessagingException e) {
Debugger.write(getSendingExceptions(e),
Debugger.DEBUG,
new File(getDirectoriLogs(),nomFitxer));
}
}
   <<Less

Re: Messages with HTML body and attachments not well formated with Netscape Messenger...

Posted By:   Edwin_Lee  
Posted On:   Thursday, July 25, 2002 01:49 AM

Are u using javamail 1.1 or 1.3?


why don't use this:


msg.setContent(missatge, "text/html");





For editting your coding, u may try for the below, but I am not sure it is what u want...






Multipart multiPart = new MimeMultipart("alternative");


MimeBodyPart htmlBody = new MimeBodyPart();





htmlBody.setText(messageText,"iso-8859-1");


htmlBody.addHeader("Content-Type","iso-8859-1");


htmlBody.addHeaderLine("Content-Type:text/html; charset="iso-8859-1"");


htmlBody.addHeaderLine("Content-Transfer-Encoding: quoted-printable");





multiPart.addBodyPart(missatge);


msg.setContent(multiPart);


About | Sitemap | Contact