• Post Reply Bookmark Topic Watch Topic
  • New Topic

JAVA MAIL not Sending

 
Aravind Prasad
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers..
I'm trying to send a mail using JAVA MAIL API
but is showing some error..

the code is this
===========================================================================

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

public class SendEmail
{
public static void main(String[] args)
{SendMessage();
System.out.println("email is sent");
}

public static String SendMessage()
{
String e_to = "aravind.prasad@ug.spedag.com";
String e_from = "siva.kumar@ug.spedag.com";
String e_host = "spu-mails";
String e_subject = "TEST";
String e_text = "Hello Aravind This is a test Email";
//return(to,from,host,Subject,Txt);

/*****************************************************/
Properties props = new Properties();
props.put("172.16.0.1", e_host);
boolean debug = false;
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);
try
{Message msg = new MimeMessage(session);
InternetAddress from = new InternetAddress(e_from);
msg.setFrom(from);
InternetAddress[] address =
{ new InternetAddress(e_to)
};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(e_subject);
msg.setContent(e_text, "text/plain");
Transport.send(msg);
}
catch(MessagingException mex)
{mex.printStackTrace();
}

return "email sent to:" +e_to;
}
}

===========================================================================
i'm using Java 1.5 SKD
and JavaMail 1.4
i set the classpath properly
still it is showing an error..

error is
--------------------------------------------------------------------------

C:\Documents and Settings\AravindPrasad\My Documents>java SendEmail
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/SharedByteArrayInputStream
at SendEmail.SendMessage(SendEmail.java:28)
at SendEmail.main(SendEmail.java:8)

---------------------------------------------------------------------------

i was trying to figure it out.. thru internet searching and all..
but failed to get a solution

Ranchers.. Please Help me..
regards
Aravind Prasad
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i set the classpath properly

JavaMail consists of 5 jar files (mail, activation, pop, smtp and imap, if memory serves correctly). Are all those accessible? Try to figure out which jar file contains the missing class, and see if that is included correctly in the classpath.
 
Aravind Prasad
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello ranchers..
the file is missing in the mail.jar.. and that file is set in the classpath..
it is also showing runtime error..when i copied that file in the directory

please help me.. ranchers.. how to solve this

thanks in advance

regards
Aravind
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure there is no typing error in the classpath? What does it look like, and what are the actual file names?
 
Paul Clapham
Sheriff
Posts: 21889
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Put mail.jar and activation.jar in your classpath. But do not put the other 3 jar files in your classpath, as they contain the same code split up differently and that can lead to problems. Also make sure that none of those 5 jars are anywhere else that they might be loaded, such as in the extensions directory.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!