public void contextInitialized(ServletContextEvent arg0) {
System.out.println("init");
SimpleMail sm = new SimpleMail();
sm.setSubject("报告电脑所在位置");
InetAddress inet = null;
try {
inet = InetAddress.getLocalHost();
} catch (UnknownHostException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String str = "当前登陆主机的ip=" + inet.getHostAddress();
// String str = ReadHtmlFile.readFile("这里填写你需要发送的本地文件路径");
sm.setContent(str);
SimpleMailSender sms = new SimpleMailSender("xxx@qq.com",
"csh8338281110");
try {
Thread.currentThread().sleep(1000);
sms.send("xxx@163.com", sm);
System.out.println("执行完成11!!");
} catch (Exception e) {
// e.printStackTrace();
try {
Thread.currentThread().sleep(1000 * 5);
sms.send("bzu901@163.com", sm);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
来至:http://blog.csdn.net/csh624366188/article/details/8479416