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;
|