You are here: DEVPPL Forum Programming Java Forum
NOTIFICATIONS
54.087
MEMBERS
15.686
TOPICS
62.258
POSTS
  562
FLASH GAMES
7.740
TUTORIALS
 

Login

E-mail:
Password:

How to get Formatted Mail Content through Java Application

0

Loading

How to get Formatted Mail Content through Java Application

Postby Randy_ortan » Mon Jan 04, 2010 1:45 pm

I am using a mail sending function in my applet code which is listed below:
Main content is fetched from a format tool bar in JSP Page and it is passed as parameter to applet and it is used inside the mail content.
Same content when passed and executed in a JSP page, the formatted content is not lost and it is included in mail content as what it is fetched from Format Tool Bar.
Format is lost when it is used inside the Java Application mail sending function.
The below code I have used to send mail:

Code: Select all
package com;

import java.util.HashSet;
import java.util.Properties;
import java.util.Set;

import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

class mailsendClass
{
public void sendmail(String from,String host,boolean debug,String msgText)
{
   try
   {
      Set tomailsid = new HashSet();
      Set ccmailsid = new HashSet();

      //to mail ids       
      tomailsid.add("test@xxx.net" );      
      tomailsid.add("test@xxx.net" );
      tomailsid.add("testing@xxx.net" );
      
      
      //cc mail ids
      ccmailsid.add("sample@xxx.net" );
      ccmailsid.add("sample1@xxx.net" );

      
      String mailarray[]= (String[])tomailsid.toArray(new String[tomailsid.size()]);
      String ccmailID[]= (String[])ccmailsid.toArray(new String[ccmailsid.size()]);
      
      Properties props = new Properties();
      //props.put("mail.smtp.port","425");
      props.setProperty("mail.smtp.host", host);
      if (debug) props.setProperty("mail.debug", ""+debug);
      Session session = Session.getInstance(props, null);
      session.setDebug(debug);

      String mailsubject = "Mail Subject";
      
      // create a message
      Message msg = new MimeMessage(session);
      msg.setFrom(new InternetAddress(from));
      javax.mail.internet.InternetAddress[] toAddress=new javax.mail.internet.InternetAddress[mailarray.length];
      
      for (int i=0;i<mailarray.length ;i++ )
      {
      toAddress[i]=new javax.mail.internet.InternetAddress(mailarray[i]);
      System.out.println ("id inside to address loop  " + i + " is  "+  mailarray[i]);
      System.out.println ("toAddress " + i + " is  "+  toAddress[i]);
      }
      msg.setRecipients(Message.RecipientType.TO, toAddress);
      msg.setSubject(mailsubject);

      try
      {
         javax.mail.internet.InternetAddress[] CCAddress=new javax.mail.internet.InternetAddress[ccmailID.length];
         for (int i=0;i<ccmailID.length ;i++ )
         {
            CCAddress[i]=new javax.mail.internet.InternetAddress(ccmailID[i]);
            System.out.println("CC Array is ===> " +CCAddress[i] );//                     
         }

          msg.setRecipients(Message.RecipientType.CC,CCAddress);
      }
      catch(Exception ss)
      {
         System.out.println("CC mail Exception is ====>"+ ss);   
      }
         
         msg.setSentDate(new java.util.Date());
       
//          Multipart multipart = new MimeMultipart("relative");
         Multipart multipart = new MimeMultipart("alternative");
          BodyPart messageBodyPart = new MimeBodyPart();
         
          messageBodyPart.setContent(msgText, "text/html");
//          messageBodyPart.setContent(msgText, "text/plain");
         
          multipart.addBodyPart(messageBodyPart);      
         msg.setContent(multipart);
          Transport.send( msg );
         
      
   }
   catch (Exception e)
   {
      System.out.println("The Exception is ------>"+e);
   }
}
}
public class SendMail {
public static void main(String[] args)
{
   System.out.println("before Mail Send ");
   
   mailsendClass mail = new mailsendClass();
   
   String from="randy@xxx.net";
   String host="172.16.2.6";
   String msgText="<p><strong>Index</strong><br />I have posted the following PDFs (Second Pages) as mentioned to start producing the Index:<br />• Engage<br />• Chapters 1–6<br /><a title='ftp:///Index' href='ftp://index/'>ftp:///Index</a><strong><br />XML Coding - Files with errors</strong><br />• Engage<br />• Chapters 1–6<br /><a title='ftp:///XML_Coding_Need%20Fixing' href='ftp://xml_coding_need%20fixing/'>ftp:///XML_Coding_Need%20Fixing</a></p>";

   mail.sendmail(from,host,true,msgText);
   System.out.println("after Mail Send ");
   
}
}
 


Content placed in format tool bar is as follows:

Index
I have posted the following PDFs (Second Pages) as mentioned to start producing the Index:
• Engage
• Chapters 1–6
ftp:///Index
XML Coding - Files with errors
• Engage
• Chapters 1–6
ftp:///XML_Coding_Need%20Fixing


Content fetched from format tool bar inside JSP page is as follows:

<p><strong>Index</strong><br />I have posted the following PDFs (Second Pages) as mentioned to start producing the Index:<br />&bull; Engage<br />&bull; Chapters 1&ndash;6<br /><a title="ftp:///Index" href="ftp://index/">ftp:///Index</a><strong><br />XML Coding - Files with errors</strong><br />&bull; Engage<br />&bull; Chapters 1&ndash;6<br /><a title="ftp:///XML_Coding_Need%20Fixing" href="ftp://xml_coding_need%20fixing/">ftp:///XML_Coding_Need%20Fixing</a></p>

Fetched Content inside Java Application through parameter and it will use as input for mail content is as follows:


<p><strong>Index</strong><br />I have posted the following PDFs (Second Pages) as mentioned to start producing the Index:<br />• Engage<br />• Chapters 1–6<br /><a title="ftp:///Index" href="ftp://index/">ftp:///Index</a><strong><br />XML Coding - Files with errors</strong><br />• Engage<br />• Chapters 1–6<br /><a title="ftp:///XML_Coding_Need%20Fixing" href="ftp://xml_coding_need%20fixing/">ftp:///XML_Coding_Need%20Fixing</a></p>

Actual mail received after Java Application execution is as follows:
Index
I have posted the following PDFs (Second Pages) as mentioned to start producing the Index:
? Engage
? Chapters 1?6
ftp:///Index
XML Coding - Files with errors
? Engage
? Chapters 1?6
ftp:///XML_Coding_Need%20Fixing
Unicode characters in the mail content are replaced by “?”.



In the function listed above I have used the MIME Setting as

Multipart multipart = new MimeMultipart("alternative");

I have tried by using “relative” MIME format also as

Multipart multipart = new MimeMultipart("relative");

But I am not getting the actual format passed as input to the Java Application in the mail content.
Can anybody let us know how to overcome this problem?
Thanks in advance.
Randy_ortan
 
Reputation: 0
Posts: 12
Joined: Thu Sep 11, 2008 7:34 am
Highscores: 0
Arcade winning challenges: 0

How to get Formatted Mail Content through Java Application - Sponsored results

Sponsored results

Login to get rid of ads

 

0

Loading

Re: How to get Formatted Mail Content through Java Application

Postby Randy_ortan » Mon Jan 04, 2010 3:01 pm

hi,

can any one please give some Suggestion.
Randy_ortan
 
Reputation: 0
Posts: 12
Joined: Thu Sep 11, 2008 7:34 am
Highscores: 0
Arcade winning challenges: 0
0

Loading

Re: How to get Formatted Mail Content through Java Application

Postby Randy_ortan » Tue Jan 05, 2010 10:32 am

hi all,

i got a solution for my above mentioned problem. so if u need any help then please refer this bug: http://www.codeguru.com/forum/showthread.php?t=490513

Thank u.
Randy_ortan
 
Reputation: 0
Posts: 12
Joined: Thu Sep 11, 2008 7:34 am
Highscores: 0
Arcade winning challenges: 0
^ Back to Top