Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
|
Java GUI Discussions specific to programming Java GUI.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java GUI section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 20th, 2008, 05:40 AM
Registered User
 
Join Date: May 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default help me about send email by java

i run the programme, but i cann't give email from mailbox, why, who can help me ,thanks in advance.


Properties props = new Properties();
        Session sendMailSession;
        Transport transport;
        //props.put("mail.smtp.host", server);

        props.put("mail.smtp.ip", "202.108.5.81");
        props.put("mail.smtp.port", "25");


       sendMailSession = Session.getDefaultInstance(props,null);
       sendMailSession.setDebug(true);
       Message newMessage;


    newMessage = new MimeMessage(sendMailSession);



       try
       {
           InternetAddress addressFrom = new InternetAddress(user);
           newMessage.setFrom(addressFrom);

           InternetAddress[] addressTo = new InternetAddress[2];
           addressTo[0] = new InternetAddress("heguang_1983");
           addressTo[1] = new InternetAddress("heguang_1983");

           newMessage.setRecipients(Message.RecipientType.TO, addressTo);

           newMessage.setSubject("SMTPcheck"); //ÉèÖÃÖ÷Ìâ

           newMessage.setSentDate(new Date()); //ÉèÖ÷¢ËÍʱ¼ä

           newMessage.setContent(text,"text/plain"); //ÉèÖ÷¢ËÍÄÚÈÝ

           PrintStream ps ;
           ps = sendMailSession.getDebugOut();

           FileOutputStream fs ;
           try
           {
               fs = new FileOutputStream("C:\\smtpMessage.txt");
               ps = new PrintStream(fs);
           }
           catch(Exception e)
           {
           }
           if(ps!=null)
           {
              System.setOut(ps);
           }
           System.out.println("SMTPÕï¶Ï±¨¸æ");



           Transport.send(newMessage);

           }
           catch (AuthenticationFailedException e)
           {
             System.out.println("µÇ½ʧ°Ü£¬Çë¼ì² éÓû§ÃûºÍÃÜÂë");
             this.jTextArea1.setText("µÇ½ʧ°Ü£¬Ç렼ì²éÓû§ÃûºÍÃÜÂë");

             return false;
           }
           catch (IllegalWriteException e)
           {
               System.out.println("µÇ½ʧ°Ü£¬Çë¼ì² éÓû§ÃûºÍÃÜÂë");
               this.jTextArea1.setText("µÇ½ʧ°Ü£¬Ç렼ì²éÓû§ÃûºÍÃÜÂë");

               return false;
           }
           catch(SMTPSendFailedException e)
           {
               System.out.println("·¢Ê§°Ü");
               this.jTextArea1.setText("·¢ËÍʧ°Ü");
               //sb.append("Çë¼ì²â½ÓÊÜÕ˺Å");
               return false;
           }
           catch(SendFailedException e)
          {
               System.out.println("ÊÕ¼þÈ˵ØÖ·²»´æÔ Ú,¼ì²âÕ˺Å");
               this.jTextArea1.setText("ÊÕ¼þÈ˵ØÖ·²» ´Ã¦Ã”Ú,¼ì²âÕ˺Å");
               return false;
               //sb.append("ÊÕ¼þÈ˵ØÖ·²»´æÔÚ,¼ì² âÕ˺Å");
           }
          catch (AddressException e)
          {
            //e.printStackTrace();
              System.out.println("·þÎñÆ÷ÓòÃû´íÎó") ;
          }
          catch (MessagingException e)
          {
              System.out.println("·þÎñÆ÷ÓòÃû´íÎó") ;
              //sb.append("·þÎñÆ÷ÓòÃû´íÎó");
              this.jTextArea1.setText("·þÎñÆ÷ÓòÃû´íà ŽÃ³");
              return false;
          }
       return true;






Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to send email garrettbrennan Visual C++ 0 September 13th, 2007 12:24 PM
Send by email tsimsha Classic ASP Databases 1 October 1st, 2005 03:03 AM
To send an email Danny_n BOOK: Excel 2003 VBA Programmer's Reference 0 January 12th, 2005 08:33 AM
Send email Danny_n BOOK: Excel 2003 VBA Programmer's Reference 0 January 12th, 2005 08:32 AM
send email X-Ken VS.NET 2002/2003 8 July 2nd, 2004 06:13 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.