当前位置:编程学习 > JAVA >>

Java邮件问题

写个了程序。 我加了一句发邮件的代码后 导出文件就不能用了。 一打开过几秒就自动关掉。 把这句话去掉之后就正常了。 这是为什么? import java.util.Properties; import javax.mail.Address; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class Mail { boolean issend; Transport transport = null; Session session = null; Message msg = null; Properties props = null; public Mail() { issend = false; } public void send(String ip) { try { props = new Properties(); props.setProperty("mail.smtp.auth", "true"); props.setProperty("mail.transport.protocol", "smtp"); session = Session.getDefaultInstance(props); msg = new MimeMessage(session); msg.setSubject("Ip Address"); msg.setText(ip); msg.setFrom(new InternetAddress("fj359941160@sina.com")); transport = session.getTransport(); transport.connect("smtp.sina.com", 25, "fj359941160", "fangjian++"); transport.sendMessage(msg, new Address[] { new InternetAddress("fj359941160@vip.qq.com") }); transport.close(); this.issend = true; } catch(Exception e) { } } }  这个发邮件的代码。  在主函数中加入 如下 : mail = new Mail(); while(!this.mail.issend) { try { Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } this.mail.send(this.getIP()); }   加入这几句后导出jar包就不能正常运行了。  去掉之后又能运行了。 这是为什么?
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,