aspose file tools*
The moose likes Other JSE/JEE APIs and the fly likes Error while sending Html Mail Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Error while sending Html Mail" Watch "Error while sending Html Mail" New topic
Author

Error while sending Html Mail

varun bihani
Ranch Hand

Joined: Aug 11, 2003
Posts: 96
I have created a java file which send mail in html format...
its giving me this error...
i dont understand wat is this all abt..
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/SharedByteArrayInputStream
at email_test_html.main(email_test_html.java:114)
can nebody help??


<a href="http://www.galaxyweblinks.com" target="_blank" rel="nofollow">www.galaxyweblinks.com</a><br /><a href="http://www.freechatcode.com" target="_blank" rel="nofollow">www.freechatcode.com</a><br /><a href="http://www.onlinefamilytreemaker.com" target="_blank" rel="nofollow">www.onlinefamilytreemaker.com</a>
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Could you please post the java code snippet where the error is occuring..


Spritle Software Blogs
varun bihani
Ranch Hand

Joined: Aug 11, 2003
Posts: 96
My Code Snippet is
This is the java file that runs everyday by Cron..
I searches the databases and takes out the email and send html format mail
import java.io.PrintStream;
import java.sql.ResultSet;
import java.util.StringTokenizer;
import java.util.Vector;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
class email_test_html
{
public email_test_html()
{
String to, subject = null, from = null,url = null;
String mailHost = "";
String protocol = null, host = null, user = null, password = null;
}
public Vector getCategoryVector(String s)
{
Vector vector = new Vector(1);
for(StringTokenizer stringtokenizer = new StringTokenizer(s, "~"); stringtokenizer.hasMoreTokens(); vector.addElement(stringtokenizer.nextToken()));
return vector;
}
public String getCategoryString(String s)
{
String s1 = "";
for(StringTokenizer stringtokenizer = new StringTokenizer(s, "~"); stringtokenizer.hasMoreTokens()
if(!s1.equals(""))
s1 = s1 + " or b.id =" + stringtokenizer.nextToken();
else
s1 = " b.id=" + stringtokenizer.nextToken();
return s1;
}
public static void main(String args[])
{
email_test_html email_test_html1 = new email_test_html();
String s1 = "";
int jj=0;
try
{
CConnection cconnection = new CConnection();
cconnection.connect();
String s2 = "select USERLOGIN,CATEGORY_MULTI_ID,EMAIL from T_REGISTRATION";
for(ResultSet resultset = cconnection.executeQuery(s2); resultset.next()
{
String s3=resultset.getString("USERLOGIN");
String s4 = resultset.getString("EMAIL");
String s5 = resultset.getString("CATEGORY_MULTI_ID");
String s6 = email_test_html1.getCategoryString(s5);
String s7 = "";
if(s4.equals("") || s4 == null)
s4 = "root@abc.com";
String s8 = "select p.id postid,p.CATEGORY_ID catid,c.name catname,b.id parentid,b.name parentname";
s8 = s8 + " from T_POST p ,T_CATEGORY c,T_CATEGORY b ";
s8 = s8 + " where p.status=1 and p.CATEGORY_ID= c.id and c.parent_id = b.id ";
if(!s6.equals(""))
if(s6.equals(" b.id=245"))
s8 =s8+ " and ( b.id =1 or b.id =49 or b.id =5 or b.id =12 or b.id =9 or b.id =15 or b.id =26 or b.id =22 or b.id =44 or b.id =40 or b.id =31 or b.id =245)";
else
s8 = s8 + " and ("+s6+") ";
s8 = s8 + " group by b.id,c.id ";
String s9 = "";
s7 = s7 + "<html><body>Dear " + s3 + ",\n\n";
s7 = s7 + "There is addition of new offers in the following category:\n";
s1 = "";
for(ResultSet resultset1 = cconnection.executeQuery(s8); resultset1.next()
{
String s10 = resultset1.getString("parentname");
String s11 = resultset1.getString("catname");
s1 = resultset1.getString("postid");
//System.out.println("Main Category--------------" + s10);
//System.out.println("Sub Category--------------" + s11);
//System.out.println("Post ID--------------" + s1);
String s12 = s10;
}
if(s1==null || s1.equals(""))
{
System.out.println("NO POSTING");
}
else{
System.out.println("1");
Properties props = new Properties();
System.out.println("2");
props.setProperty("mail.smtp.host", "");
System.out.println("3");
Session ssn = Session.getDefaultInstance(props);
System.out.println("4");
ssn.setDebug(true);
System.out.println("5");
Message msg = new MimeMessage(ssn);
System.out.println("6");
InternetAddress fromAdd = new InternetAddress("admin@chemicalhouse.com");
System.out.println("7");
msg.setFrom(fromAdd);
System.out.println("8");
msg.setSubject("Entry Posting Mail");
System.out.println("9");
InternetAddress toAdd = new InternetAddress("varunbihani@rediffmail.com");
System.out.println("10");
msg.addRecipient(Message.RecipientType.TO, toAdd);
System.out.println("11");
msg.setContent(s7, "text/html");
Transport.send(msg);
//sent=true;
}
}
}
catch(Exception exception)
{
System.out.println("EEEEEEERRRRRRRRROOOOOOORRRR" + exception);
}
}
}
 
 
subject: Error while sending Html Mail