用Javamail写的邮件接收程序 - 编程入门网
作者 佚名技术
来源 NET编程
浏览
发布时间 2012-06-24
teformat = format; } /** * 【获得附件存放路径】 */ public String getAttachPath(){ return saveAttachPath; } /** * 【真正的保存附件到指定目录里】 */ private void saveFile(String fileName,InputStream in)throws Exception{ String osName = System.getProperty("os.name"); String storedir = getAttachPath(); String separator = ""; if(osName == null) osName=""; if(osName.toLowerCase().indexOf("win") != -1){ separator = "\\" if(storedir == null || storedir.equals("")) storedir="c:\\tmp"; }else{ separator = "/"; storedir = "/tmp"; } File storefile = new File(storedir+separator+fileName); System.out.println("storefile''s path: "+storefile.toString()); //for(int i=0;storefile.exists();i++){ //storefile = new File(storedir+separator+fileName+i); //} BufferedOutputStream bos = null; BufferedInputStream bis = null; try{ bos = new BufferedOutputStream(new FileOutputStream(storefile)); bis = new BufferedInputStream(in); int c; while((c=bis.read()) != -1){ bos.write(c); bos.flush(); } }catch(Exception exception){ exception.printStackTrace(); throw new Exception("文件保存失败!"); }finally{ bos.close(); bis.close(); } } /** * PraseMimeMessage类测试 */ public static void main(String args[])throws Exception{ String host = "主机名/ip"; //【pop.mail.yahoo.com.cn】 String username ="用户名"; //【wwp_1124】 String password ="密码"; //【........】 Properties props = new Properties(); Session session = Session.getDefaultInstance(props, null); Store store = session.getStore("pop3"); store.connect(host, username, password); Folder folder = store.getFolder("INBOX"); folder.open(Folder.READ_ONLY); Message message[] = folder.getMessages(); System.out.println("Messages''s length: "+message.length); PraseMimeMessage pmm = null; for(int i=0;i<message.length;i++){ pmm = new PraseMimeMessage((MimeMessage)message[i]); System.out.println("Message "+i+" subject: "+pmm.getSubject()); System.out.println("Message "+i+" sentdate: "+pmm.getSentDate()); System.out.println("Message "+i+" replysign: "+pmm.getReplySign()); System.out.println("Message "+i+" hasRead: "+pmm.isNew()); System.out.println("Message "+i+" containAttachment: "+pmm.isContainAttach((Part)message[i])); System.out.println("Message "+i+" form: "+pmm.getFrom()); System.out.println("Message "+i+" to: "+ |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于用Javamail写的邮件接收程序 - 编程入门网的所有评论