473,386 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

error with mail progmming

dmjpro
2,476 2GB
i have no problem while i complile the program.
this is my source code ......

Expand|Select|Wrap|Line Numbers
  1. import javax.mail.*;
  2. import javax.mail.internet.*;
  3. import java.util.*;
  4.  
  5. class MailTest1
  6. {
  7.         public static void main(String args[])
  8.         {
  9.                try
  10.                    {
  11.                         if(args.length == 0)
  12.                         {
  13.                                 throw new Exception("Insufficient arguments ....");
  14.                         }
  15.                          String smtpServer=args[0];
  16.                          String to=args[1];
  17.                          String from=args[2];
  18.                          String subject=args[3];
  19.                          String body=args[4];
  20.                          send(smtpServer, to, from, subject, body);
  21.                    }
  22.                    catch (Exception ex)
  23.                                       {
  24.                         System.out.println("Exception in main: " + ex.getMessage());
  25.                    }
  26.         }
  27.         public static void send(String smtpServer, String to, String from
  28.            , String subject, String body)
  29.         {
  30.                 try
  31.                 {
  32.                         Properties props = System.getProperties();
  33.                         // -- Attaching to default Session, or we could start
  34.                         props.put("mail.smtp.host", smtpServer);
  35.                         Session session = Session.getDefaultInstance(props, nu
  36.                         // -- Create a new message --
  37.                         Message msg = new MimeMessage(session);
  38.                         // -- Set the FROM and TO fields --
  39.                         msg.setFrom(new InternetAddress(from));
  40.                         msg.setRecipients(Message.RecipientType.TO,
  41.                                                 InternetAddress.parse(to, false));
  42.                         // -- We could include CC recipients too --
  43.                         // if (cc != null)
  44.                         // msg.setRecipients(Message.RecipientType.CC
  45.                         // ,InternetAddress.parse(cc, false));
  46.                         // -- Set the subject and body text --
  47.                         msg.setSubject(subject);
  48.                         msg.setText(body);
  49.                         // -- Set some other header information --
  50.                         msg.setHeader("X-Mailer", "LOTONtechEmail");
  51.                         msg.setSentDate(new Date());
  52.                         // -- Send the message --
  53.                         Transport.send(msg);
  54.                         System.out.println("Message sent OK.");
  55.                 }
  56.                 catch (Exception ex)
  57.                 {
  58.                         System.out.println("Exception in send: " + ex.getMessage());
  59.                 }
  60.         }
  61. }
  62.  
but when i run the program then i get an error ......

Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/Message

plz help...
it's urgent

kind regards,
dmjpro.
Jun 13 '07 #1
6 1361
JosAH
11,448 Expert 8TB
That package is supposed to be an extension so you should put that .jar in
the 'ext' directory under the lib directory of your JRE.

kind regards,

Jos
Jun 13 '07 #2
dmjpro
2,476 2GB
That package is supposed to be an extension so you should put that .jar in
the 'ext' directory under the lib directory of your JRE.

kind regards,

Jos
then why didn't i get the compiling error?
plz explain.

kind regards,
dmjpro.
Jun 13 '07 #3
dmjpro
2,476 2GB
then why didn't i get the compiling error?
plz explain.

kind regards,
dmjpro.

Ok i solved it.
but i have a new problem .. how can i get host name for a mail server... sayGMAIL server?
plz help.

kind regards,
Dmjpro.
Jun 13 '07 #4
JosAH
11,448 Expert 8TB
Ok i solved it.
but i have a new problem .. how can i get host name for a mail server... sayGMAIL server?
plz help.

kind regards,
Dmjpro.
You can't; your program has to "know" it in advance. There is no service that
gives you a list of smtp servers anywhere in the world.

kind regards,

Jos
Jun 13 '07 #5
dmjpro
2,476 2GB
You can't; your program has to "know" it in advance. There is no service that
gives you a list of smtp servers anywhere in the world.

kind regards,

Jos

so do u know those server names for common use mail serveres????
plzzz say...

kind regards,
dmjpro.
Jun 13 '07 #6
JosAH
11,448 Expert 8TB
so do u know those server names for common use mail serveres????
plzzz say...

kind regards,
dmjpro.
I only know the name of the smtp server supplied by my ISP.

kind regards,

Jos
Jun 13 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that...
1
by: jam | last post by:
Dear All, I am writing a console and it send a email out when it hits error it calls this static void SendErrorEmail(string error) { System.Web.Mail.MailMessage mail = new...
0
by: Erwan | last post by:
I have a strange (but very blocking) result when using the smtpmail class from an ASPX page : here is the (very simple !) code... '-------------------------------------------------- mail.To =...
9
by: B-Dog | last post by:
I've built a small app that sends mail through our ISP's SMTP server but when I try to send through my local exchange server I get CDO error. Does webmail use SMTP or does it strictly rely on...
5
by: Nathan Sokalski | last post by:
I am attempting to send an email using ASP.NET 1.1's Mail.SmtpMail.Send() method. My code contains all of the following: Dim mailmsg As New Mail.MailMessage Mail.SmtpMail.SmtpServer =...
2
by: =?Utf-8?B?QWRl?= | last post by:
HI All, I am encountering the following error when I try to send an email through a SMTP server. I believe the problem lies with the authentication part when the network crednetials are used,...
2
by: satnamsarai | last post by:
Using System.Net.Mail: Sometimes I get error 'failure sending mail. Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.' Not sure how...
6
by: Dave Kelly | last post by:
Sorry for the long post, it is easier to discard information than to have to wait for it to arrive. So here goes: This code worked perfectly when I was an Earthlink customer. Sprint decided...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.