java培训_博益教育 java培训就业班_博益教育

                                          当前位置:博益教育 > java热点 >

                                          JavaMail邮件发送-将邮件保存到本地和发送一封本地邮件
                                          栏目分类:java热点   发布日期:2025-01-27   浏览次数:337

                                          普通是如许的,尔们大概没有会请求立地收收那启邮件,为了加少效劳器压力战带阔压力,尔们普通是正在闲暇时正在收收,大概用户指守时间才收收

                                          那末便要先把邮件停止保管,而后守时收收

                                          能够将疑息保管到数据库,而后获得后再拼装邮件疑息,那里尔们便把邮件挨成1个文献保管正在要地

                                          保管到内地很复杂,只需之前您的示例皆能跑通,只好1步

                                          packagecom.mail;importjava.io.File;importjava.io.FileOutputStream;importjava.io.OutputStream;importjava.util.Date;importjava.util.Properties;importjavax.mail.Message;importjavax.mail.Session;importjavax.mail.internet.InternetAddress;importjavax.mail.internet.MimeMessage;importjavax.mail.internet.MimeUtility;/***@诠释保管1个邮件*@authorcuisuqiang*@version1.0*@since*/publicclassTextMail{publicstaticvoidmain(String[]args)throwsException{Propertiesprops=newProperties();props.put("mail.smtp.host","smtp.163.com");props.put("mail.smtp.port",25);props.put("mail.smtp.auth","true");Sessionsession=Session.getInstance(props);session.setDebug(true);Messagemessage=newMimeMessage(session);InternetAddressfrom=newInternetAddress("test20120711120200@163.com");from.setPersonal(MimeUtility.encodeText("java小强<test20120711120200@163.com>"));message.setFrom(from);InternetAddressto=newInternetAddress("test20120711120200@163.com");message.setRecipient(Message.RecipientType.TO,to);message.setSubject(MimeUtility.encodeText("强哥恭请,谁敢没有从!"));message.setText("强哥聘请您拜候尔的专客:http://cuisuqiang.iteye.com/");message.setSentDate(newDate());//邮件对于象Filefile=newFile("C:\\textmail.eml");//得到输入淌OutputStreamips=newFileOutputStream(file);//把邮件内乱容写进到文献message.writeTo(ips);//闭关淌ips.close();System.out.println("收收告终");}}

                                          邮件对于象创造后不当即收收,而是保管到了1个文献中

                                          那末怎样收收1启仍然生存的邮件呢?也很复杂,仅仅邮件对于象的树立的体例没有一致了罢了

                                          packagecom.mail;importjava.io.File;importjava.io.FileInputStream;importjava.util.Date;importjava.util.Properties;importjavax.mail.Message;importjavax.mail.Session;importjavax.mail.Transport;importjavax.mail.internet.MimeMessage;/***抓紧1启现有邮件*@authorcuisuqiang@163.com*/publicclassSendCurrentMail{publicstaticvoidmain(String[]args)throwsException{Propertiesprops=newProperties();props.put("mail.smtp.auth","true");Sessionsession=Session.getInstance(props);//现有邮件文献Filefile=newFile("C:\\textmail.eml");FileInputStreamfis=newFileInputStream(file);//成立邮件对于象Messagemessage=newMimeMessage(session,fis);message.setSentDate(newDate());message.saveChanges();//收收邮件Transporttransport=session.getTransport("smtp");transport.connect("smtp.163.com",25,"test20120711120200","test123456");transport.sendMessage(message,message.getAllRecipients());transport.close();fis.close();System.out.println("收收收场");}}

                                          固然,详细交易中的运用必定要添补很多判定的,出格是设想到了文献的掌握,尔那里便没有再11的讲授了!

                                          JavaMail邮件发送-将邮件保存到本地和发送一封本地邮件

                                          推举您浏览更多相关于“ JavaMail邮件当地邮件 ”的作品

                                          
                                          Copyright © 2024-2026  java培训_博益教育 java培训就业班_博益教育   http://www.taigangzhonglian.com  .All Rights Reserved   网站地图  无
                                          博益教育 java项目 java热点 联系我们