error with mail progmming

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #1

    error with mail progmming

    i have no problem while i complile the program.
    this is my source code ......

    [code=java]
    import javax.mail.*;
    import javax.mail.inte rnet.*;
    import java.util.*;

    class MailTest1
    {
    public static void main(String args[])
    {
    try
    {
    if(args.length == 0)
    {
    throw new Exception("Insu fficient arguments ....");
    }
    String smtpServer=args[0];
    String to=args[1];
    String from=args[2];
    String subject=args[3];
    String body=args[4];
    send(smtpServer , to, from, subject, body);
    }
    catch (Exception ex)
    {
    System.out.prin tln("Exception in main: " + ex.getMessage() );
    }
    }
    public static void send(String smtpServer, String to, String from
    , String subject, String body)
    {
    try
    {
    Properties props = System.getPrope rties();
    // -- Attaching to default Session, or we could start
    props.put("mail .smtp.host", smtpServer);
    Session session = Session.getDefa ultInstance(pro ps, nu
    // -- Create a new message --
    Message msg = new MimeMessage(ses sion);
    // -- Set the FROM and TO fields --
    msg.setFrom(new InternetAddress (from));
    msg.setRecipien ts(Message.Reci pientType.TO,
    InternetAddress .parse(to, false));
    // -- We could include CC recipients too --
    // if (cc != null)
    // msg.setRecipien ts(Message.Reci pientType.CC
    // ,InternetAddres s.parse(cc, false));
    // -- Set the subject and body text --
    msg.setSubject( subject);
    msg.setText(bod y);
    // -- Set some other header information --
    msg.setHeader(" X-Mailer", "LOTONtechEmail ");
    msg.setSentDate (new Date());
    // -- Send the message --
    Transport.send( msg);
    System.out.prin tln("Message sent OK.");
    }
    catch (Exception ex)
    {
    System.out.prin tln("Exception in send: " + ex.getMessage() );
    }
    }
    }
    [/code]

    but when i run the program then i get an error ......

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

    plz help...
    it's urgent

    kind regards,
    dmjpro.
    Last edited by JosAH; Jun 13 '07, 06:24 AM. Reason: added a missing quote; the message looked terrible
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    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

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by JosAH
      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.

      Comment

      • dmjpro
        Top Contributor
        • Jan 2007
        • 2476

        #4
        Originally posted by dmjpro
        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.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by 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.
          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

          Comment

          • dmjpro
            Top Contributor
            • Jan 2007
            • 2476

            #6
            Originally posted by JosAH
            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.

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by dmjpro
              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

              Comment

              Working...