聽 Nowadays open-source has played a greater role in the IT industry, but by most of the university students in China are still little known. Domestic open-source platform and the main student areas devoted to small communities, to a certain extent, reduce the student's interest to participate. Moreover, many students have nowhere to practice with warm hands, resulting in a lack of practical experience and the ability to develop, directly affecting the quality of computer education.
聽 OpenCampus is an open-source platform for the specific development of university students. This in itself is developed by students, and strive to be more appropriate to the situation and needs of university students in China. OpenCampus has the majority of functions of the mainstream open-source platform(eg sourceforge, cosoft), and the addition of code stack sharing, curriculum design management and other functional modules for students. Through OpenCampus, students at the same time recognizing the open-source world, and get involved in the development process as well which will bring them practice,team co-operation and some other valuable experience. Minded people can have more conmmunications too.
聽 We have also communicated with the school and consensus. We will vigorously develop the school's open-source popularization and workfully mobilize the student's capability of independent innovation. Even in the near future the independence credits based on OpenCampus will be devoted.
聽 Therefore, we hope to draw on the strength of cosoft letting more like-minded people join us, together with the optimal design of the platform, to contributed to the popularization of open-source in China unniversity!
涓.閭歡鐨勫彂閫?br />聽 絎竴浠惰鐭ラ亾鐨勪簨鎯呮槸,浣犵殑SMTP鏈嶅姟鍣ㄧ殑涓繪満鍚?瀹冭礋璐e皢鎮(zhèn)ㄧ殑閭歡鍙戦佸埌澶栭儴涓栫晫鐨勬満鍣?涓鑸潵璇磋繖浜涙湇鍔″櫒閮界鍚堝懡鍚嶄範(fàn)鎯?姣斿,濡傛灉浣犵殑閭鏄?a href="mailto:acmilan@sina.com.cn">acmilan@sina.com.cn,閭d箞SMTP鏈嶅姟鍣ㄧ殑涓繪満鍚嶅垯鏄痵mtp.sina.com.cn;鍙﹀涔熷彲浠ュ弬鑰冨悇澶х綉绔欒嚜宸辯殑璇存槑.涓轟簡鏂逛究,涓嬫枃涓互緗戞槗閭涓轟緥.
聽 JavaMail浣跨敤浜哠ession綾葷殑姒傚康鏉ヤ繚瀛樿濡係MTP涓繪満鍜岃璇佺殑淇℃伅錛屼富瑕佹兂娉曟槸鍩轟簬浼?xì)璇濆Q圫essions錛夊湪Java铏氭嫙鏈轟腑鍙互琚殧紱伙紝榪欏彲浠ラ樆姝㈡伓鎰忎唬鐮佺獌鍙栧叾浠栫敤鎴峰湪鍏朵粬浼?xì)璇濅腑鐨勪俊鎭Q岃繖浜涗俊鎭彲鑳藉寘鎷敤鎴峰悕鍜屽瘑鐮佺瓑璁よ瘉淇℃伅.浣犳墍瑕佸彂閫佺殑閭歡灝嗕繚瀛樺湪涓涓狹essage瀵硅薄涓?鑰岃繖涓狹essage瀵硅薄鍒欐槸鐢變綘鎵鏋勯犵殑session瀹炰緥鏉ュ垱寤?br />聽 瑕佸緱鍒頒竴涓壒瀹氱殑session瀵硅薄,鍙互閫氳繃涓涓嬩唬鐮?
聽聽聽聽聽 //璁劇疆session鐨勫睘鎬?br />聽聽聽聽聽 Properties pro = new Properties();
聽聽聽聽聽 pro.put("mail.transport.protocol", "smtp");
聽聽聽聽聽 pro.put("mail.smtp.auth", "true");
聽聽聽聽聽 pro.put("mail.smtp.host", "smtp.126.com");
聽聽聽聽聽 pro.put("mail.host", "126.com");
聽聽聽聽聽
聽聽聽聽聽 //璁劇疆璁よ瘉鍣?br />聽聽聽聽聽 PopupAuthenticator pop = new PopupAuthenticator();
聽聽聽聽聽 pop.performCheck("My Name", "My Password");//浣犵殑甯愭埛鍜屽瘑鐮?br />聽聽聽聽聽
聽聽聽聽聽 //寰楀埌session
聽聽聽聽聽 Session mailSession = Session.getInstance(pro, pop);
聽 瑕佹敞鎰忕殑鏄?涓轟簡閬垮厤鍨冨溇閭歡,澶у鏁扮殑smtp鏈嶅姟鍣ㄩ渶瑕佽璇?SMTP璁よ瘉(SMTP AUTH)闇瑕佺敤鎴峰悕鍜屽瘑鐮佹潵鍙戦侀偖浠?鍥犳,蹇呴』鍦╯ession鐨勫垵濮嬪寲鍙傛暟涓緗竴涓璇佽咃紙Authenticator錛夋潵榪斿洖鎵闇鐨勮璇佽瘉涔?鍏蜂綋浠g爜蹇呴』鐢辮嚜宸辨潵瀹炵幇:
聽聽聽聽 class PopupAuthenticator extends Authenticator {
聽聽聽聽聽聽 String username = null;
聽聽聽聽聽聽 String password = null;
聽聽聽聽聽聽 public PopupAuthenticator() {}
聽聽聽聽聽聽 public PasswordAuthentication performCheck(String user, String pass) {
聽聽聽聽聽聽聽聽 username = user;
聽聽聽聽聽聽聽聽 password = pass;
聽聽聽聽聽聽聽聽 return getPasswordAuthentication();
聽聽聽聽聽聽聽 }
聽聽聽聽聽聽 protected PasswordAuthentication getPasswordAuthentication() {
聽聽聽聽聽聽聽聽 return new PasswordAuthentication(username, password);
聽聽聽聽聽聽聽 }
聽聽聽聽聽 }
聽 鎺ョ潃,灝卞彲浠ョ敤涔嬪墠寰楀埌鐨剆ession鏉ユ瀯閫燤essage瀵硅薄:
聽聽聽 Message msg = new MimeMessage(mailSession);聽
聽 鍦ㄤ嬌鐢ㄤ細(xì)璇濆垱寤轟簡涓涓狹imeMessage鍚?鎴戜滑闇瑕佹潵濉厖榪欎釜娑堟伅.棣栧厛鏄緗〃澶翠俊鎭?Message綾誨畾涔変簡閭歡緋葷粺涓嬌鐢ㄧ殑灞炴?鐢卞悕瀛?鍊煎緇勬垚,浣跨敤榪欎簺鍚嶅瓧-鍊煎彲浠ユ寚瀹氶偖浠惰〃澶翠俊鎭?Javamail鎻愪緵浜嗕竴緋誨垪api鐢ㄤ簬璁劇疆甯歌鐨勯偖浠惰〃澶?鍏朵腑鍦ㄦ秹鍙?qiáng)鍦板潃鐨勬搷浣滄椂,鎴戜滑鐢↖nternetAddress鏉ヨ繘琛屽皝瑁?
聽聽聽聽聽 msg.setFrom(new InternetAddress ("acmilan@126.com");
聽聽聽聽聽 msg.setSubject("Hello");
聽聽聽聽聽 msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("intermilan@126.com", false));
聽聽聽聽聽 msg.setText("I will beat u");
聽聽聽聽聽 msg.setSentDate(new Date());
聽聽聽聽聽 //鍙戦佹秷鎭?br />聽聽聽聽聽 Transport.send(msg);
聽 瀵筎ransport綾葷殑璋冪敤灝嗕細(xì)鍘繪煡鎵鵑傚綋鐨勪細(xì)璇濓紝騫舵壘鍑哄浣曞彂閫佹秷鎭紝灝界榪欐牱鍋氱湅涓婂幓鏈変簺涓嶇洿瑙傘傚綋鎴戜滑瀹屾垚榪欎竴姝ョ殑鏃跺欙紝鎴戜滑鐨勯偖浠跺氨宸茬粡鍙戦佸嚭鍘諱簡銆傛鏃訛紝鎴戜滑榪橀渶瑕佹坊鍔犱唬鐮佹潵鎹曡幏涓夌JavaMail鍙兘鎶涘嚭鐨勫紓甯革紝瀹冧滑鏄疉ddressException銆丮essagingException鍜孶nsupportedEncodingException. 浣嗚繖灝辨槸鏈鍩烘湰鐨勪嬌鐢↗avaMail鍙戦侀偖浠剁殑鏂規(guī)硶銆?br />聽 鏈夋椂鍊欐垜浠繕闇瑕佺粰閭歡娣誨姞闄勪歡.鍐嶅洖鍒頒箣鍓嶅Message鐨勮璁轟腑,Message瀵硅薄鍚屾牱瀹氫箟浜嗛偖浠剁殑鍐呭,瀹冨彲浠ュ畾涔変竴涓秷鎭唴瀹?涔熷彲浠ュ畾涔夊涓秷鎭唴瀹?娑堟伅鍐呭(閫氬父鎸囩殑鏄檮浠?閮藉皢鐢盌ataHandle涓嬬殑綾繪潵澶勭悊.Message瀵硅薄鐢盡ultipart緇勬垚,涓涓狹ultipart鍙惈鏈夊涓狟odyPart,榪欎簺BodyPart灝嗙敤鏉ヤ繚瀛樻枃鏈俊鎭拰闄勪歡.
聽聽聽聽聽 MimeMultipart multipart = new MimeMultipart();
聽聽聽聽聽 BodyPart msgBodyPart = new MimeBodyPart();//鐢ㄦ潵鏀劇疆鏂囨湰鍐呭
聽聽聽聽聽 msgBodyPart.setContent(message, "text/plain");
聽聽聽聽聽 BodyPart attBodyPart = new MimeBodyPart();//鐢ㄦ潵鏀劇疆闄勪歡
聽聽聽聽聽 DataSource ds = new FileDataSource(new File("c:/td.txt"));
聽聽聽聽聽 attBodyPart.setDataHandler(new DataHandler(ds));//璁劇疆DataHandler
聽聽聽聽聽 attBodyPart.setFileName("bsbs.txt");//闄勪歡鐨勬樉紺哄悕瀛?br />聽聽聽聽聽 multipart.addBodyPart(msgBodyPart);
聽聽聽聽聽 multipart.addBodyPart(attBodyPart);
聽聽聽聽聽 msg.setContent(multipart);
聽聽聽聽聽 Transport.send(msg);
聽聽 鏈鍚?鎴戜滑鏉ョ湅鐪嬪浣曞彂閫丠TML鏍煎紡鐨勯偖浠?鏂囨湰鐨勬牸寮忓繀欏葷浉搴旂殑璁劇疆涓簍ext/html,閭歡涓殑鍥劇墖灝嗕互闄勪歡褰㈠紡鍔犺澆,鍙﹀榪樿鎸囧畾涓涓唴閮↖D浠ヤ緵璋冪敤;
聽聽聽聽聽 MimeMultipart multipart = new MimeMultipart();
聽聽聽聽聽 BodyPart msgBodyPart = new MimeBodyPart();
聽聽聽聽聽 //璁劇疆鏍煎紡涓?text/html"
聽聽聽聽聽 msgBodyPart.setContent("<H1>Hi! From HtmlJavaMail</H1> <img src=\"cid:logo\"/>", "text/html");
聽聽聽聽聽 BodyPart embedImage = new MimeBodyPart();
聽聽聽聽聽 DataSource ds = new URLDataSource(new URL("聽聽聽聽聽 embedImage.setDataHandler(new DataHandler(ds));
聽聽聽聽聽 //璁劇疆琛ㄥご鐨勫唴閮↖D,娉ㄦ剰,鎵璁劇疆鍐呭蹇呴』涓庡墠鏂囧搴?鍦ㄦ澶?鍓嶆枃鐨勫紩鐢ㄤ負(fù)<img src=\"cid:logo\"/>,鍥犳Content-ID琛ㄥご瀵瑰簲
聽聽聽聽聽 //鐨勫簲璇ユ槸<logo>
聽聽聽聽聽 embedImage.setHeader("Content-ID", "<logo>");
聽聽聽聽聽 multipart.addBodyPart(msgBodyPart);
聽聽聽聽聽 multipart.addBodyPart(embedImage);
聽聽聽聽聽 msg.setContent(multipart);
聽聽 榪欐牱,涓灝丠TML鏍煎紡鐨勯偖浠朵究瀹屾垚浜?br />聽聽聽聽聽 Transport.send(msg);
浜?閭歡鐨勬敹鍙?br />聽 鍚屾牱,絎竴姝ヨ繕鏄鑾峰緱鏈嶅姟鍣ㄧ殑鍚嶅瓧.鎴戜滑榪樻槸浠ョ綉鏄撲負(fù)渚?
聽 鎺ユ敹閭歡鍖呭惈涓や釜鍗忚錛屽嵆POP3鍜孖MAP銆侾OP3鏄佸崗璁紝瀹冩彁渚涗竴涓崟涓鏀朵俊綆憋紝浠ュ瓨鏀句竴瀹氶『搴忕殑閭歡淇℃伅銆侷MAP鐩稿姣旇緝鏂幫紝瀹冧負(fù)閭歡鎻愪緵榪炴帴鍒頒竴涓眰嬈″叧緋葷殑鏂囦歡鍏ュ彛錛屽叾涓竴涓叆鍙e嵆涓烘敹淇$銆傚綋鐒惰繕鏈夊叾瀹冨彲浠ヤ嬌鐢ㄧ殑鍗忚錛孭OP3鍜孖MAP鍙槸鍏朵腑涓縐嶅畨鍏ㄦу緢濂界殑鍗忚銆侸avaMail灝嗚繖浜涘崗璁彁鐐間負(fù)涓縐嶉偖浠朵粨搴?Store)鐨勬蹇碉紝榪欎竴浠撳簱涓烘枃浠剁瓑綰х殑闆嗗悎銆傝繖縐嶆彁鐐兼剰鍛崇潃浠撳簱鍖呭惈寰堝鍐呭錛屼絾鎴戜滑鍙渶瑕佸紕娓呮鍦ㄤ竴涓湇鍔℃枃浠跺す涓祻瑙堜笌瀵艱埅閭歡淇℃伅鐨勮繃紼嬶紝鑰屽疄闄呭鐞嗛偖浠跺崗璁殑浠誨姟鍒欓氳繃JavaMail璋冪敤Provider鏉ュ畬鎴?涓嶅悓鐨勫崗璁搴斾笉鍚岀殑provider銆?br />聽 JavaMail鐨凱rovider鎿嶄綔鏈嶅姟浜嶱OP3鍜孖MAP錛屼綘涔熷彲浠ュ皢鍙﹀鐨凱roviders宓屽叆鍒癑avaMail API浠ュ鐞嗗叾瀹冭濡侼NTP鎴栨湰鍦板瓨鍌ㄩ偖浠剁殑鍗忚銆傚湪Sun涓婚〉涓婂垪鍑鴻繖鏂歸潰鐨勭涓夋柟Providers銆?br />聽 鍦↗avamail涓?store鍜宖older綾繪槸鐢ㄦ潵瀛樺偍鍜屾帴鍙楁秷鎭?store鐢卞叿浣撶殑session寰楀埌,瀹冧嬌鐢ㄥ彲甯﹀弬鏁扮殑connect鏂規(guī)硶涓庢湇鍔″櫒榪炴帴,folder鍒欏拰File鏈夌偣綾諱技,鍙互灝嗗叾姣斾綔windows涓嬬殑鏂囦歡澶?瀹㈡埛鐢眘tore綾諱腑鍙栧緱folder,鍐嶅folder榪涜鎿嶄綔--榪涘叆鐗瑰畾鐨刦older,璇誨彇folder涓殑娑堟伅.
聽聽聽聽 Session session;
聽聽聽聽 Store store = null;
聽聽聽聽 Folder folder = null;
聽聽聽聽 Folder inboxfolder = null;
聽聽聽聽
聽聽聽聽 Properties props = System.getProperties();
聽聽聽聽 props.setProperty("mail.pop3s.rsetbeforequit", "true");//榪欐牱璇誨彇閭歡鏃舵湇鍔″櫒涓嶄細(xì)鍒犻櫎鍘熸湁鐨勯偖浠?br />聽聽聽聽 props.setProperty("mail.pop3.rsetbeforequit", "true");
聽聽聽聽 session = Session.getInstance(props, null);
聽聽聽聽 store = session.getStore("pop3");//閫氳繃"pop3"寰楀埌閫傚綋鐨刾rovider
聽聽聽聽 store.connect(emailserver, emailuser, emailpassword);
聽聽聽聽 folder = store.getDefaultFolder();//寰楀埌榛樿鐨勯《綰ф枃浠跺す
聽 姣忎竴Folder鍙互鍖呭惈寰堝鍏跺畠鐨勬枃浠跺す,閫氳繃getFolder鏂規(guī)硶鏉ユ祻瑙堢壒瀹氭枃浠跺す銆侷NBOX鏄偖浠舵湇鍔″櫒琛ㄧず鐨勪富鏂囦歡澶逛繚鐣欑殑鍚嶇О,pop3鍜宨map瀛樺偍閮戒細(xì)鎻愪緵涓涓狪NBOX鏂囦歡澶?
聽聽聽聽 inboxfolder = folder.getFolder("INBOX");
聽聽聽聽 inboxfolder.open(Folder.READ_ONLY);//鍙妯″紡
聽聽聽聽 Message[] msgs = inboxfolder.getMessages();
聽 闇瑕佹敞鎰忕殑鏄?姝ゆ椂鐪熸鐨勬秷鎭璞″茍娌℃湁瀛樺偍鍒版暟緇?msgs)涓?鏁扮粍淇濆瓨鐨勫彧鏄繖浜涙秷鎭璞$殑寮曠敤,鍙湁鍦ㄨ皟鐢ㄤ簡鍏蜂綋鐨凪essage.getXX()鏂規(guī)硶鏃?紼嬪簭鎵嶄細(xì)鍐嶆榪炴帴鏈嶅姟鍣ㄥ茍鍙栧緱鐪熸鐨勭粨鏋?濡傛灉瑕佽繘琛屽閭歡鐨勭瓫閫夊伐浣?涓嶅仠鐨勮皟鐢ㄦ瘡涓秷鎭璞$殑getXX鏂規(guī)硶鏃犵枒浼?xì)濯勫搷鎬ц兘.鍥犳鎴戜滑鍙互鐢‵etchProfile綾繪潵棰勫厛鎶撳彇鎰熷叴瓚g殑閮ㄥ垎鍐呭(濡傚悇琛ㄥご鍐呭),榪欏氨涓嶉渶瑕佹瘡嬈¤皟鐢╣etXX鏂規(guī)硶鏃墮兘鍐嶈繛鎺ユ湇鍔″櫒浜?
聽聽聽聽 FetchProfile fp = new FetchProfile();
聽聽聽聽 fp.add("Subject");//鍗沖彧璇誨彇涓婚淇℃伅
聽聽聽聽 inboxfolder.fetch(msgs, fp);//棰勮鍙栨瘡涓秷鎭殑涓婚
聽聽聽聽 for (int j = 0 ;j <msgs.length; j++) {
聽聽聽聽聽聽聽 if (msgs[j].getSubject().startsWith("^_^")) {//鍙鏍囬涓?^_^"鐨勯偖浠惰繘琛屾搷浣?br />聽聽聽聽聽聽聽聽聽 .......
聽聽聽聽聽聽聽 }
聽 鎺ヤ笅鏉?灝卞彲浠ヨ皟鐢∕essage鐨勫悇縐嶆柟娉曞閭歡榪涜鎿嶄綔浜?瀵逛笉鍚屾牸寮忕殑閭歡,鍏蜂綋鐨勬搷浣滃綋鐒朵篃鐣ュ井涓嶅悓.涓涓仛娉曟槸瀵規(guī)瘡涓叿浣撶殑BodyPart榪涜鎿嶄綔,閫氳繃涓嬪垪鐨勯掑綊鏂規(guī)硶鍙互鑾峰緱姣忎釜BodyPart鐨勫紩鐢?br />聽聽聽聽 private void extractPart(final Part part) throws MessagingException,IOException {
聽聽聽聽聽聽 if(part.getContent() instanceof Multipart) {
聽聽聽聽聽聽聽聽聽聽 Multipart mp=(Multipart)part.getContent();
聽聽聽聽聽聽聽聽聽聽 for (int i = 0; i < mp.getCount(); i++) {
聽聽聽聽聽聽聽聽聽聽聽聽聽聽 extractPart(mp.getBodyPart(i));
聽聽聽聽聽聽聽聽聽聽 }
聽聽聽聽聽 return;
聽聽聽 }
聽 Part鐨刧etContentType鏂規(guī)硶鍙互涓烘垜浠鍏墮噰鍙栦綍縐嶆柟娉曞鐞嗘彁渚涗緷鎹?br />聽聽聽聽 part.getContentType().startsWith("text/plain").....
聽 濡傛灉鏄互"text/plain"鎴栬?text/html"寮澶?閫氬父鎴戜滑鍙互鐩存帴鍙栧嚭鍏跺唴瀹?br />聽聽聽 bodytext = (String) part.getContent();
聽 濡傛灉涓よ呴兘涓嶆槸,鎴戜滑灝嗗叾瑙嗕箣涓洪檮浠?閫氳繃IO嫻佹潵璇誨彇:
聽聽聽聽聽 InputStream in = part.getInputStream();//璇誨彇part涓殑闄勪歡
聽聽聽聽聽 ByteArrayOutputStream bos = new ByteArrayOutputStream();
聽聽聽聽聽 byte[] buffer = new byte[8192];
聽聽聽聽聽 int count = 0;
聽聽聽聽聽 while ( (count = in.read(buffer)) >= 0) {
聽聽聽聽聽聽聽 bos.write(buffer, 0, count);
聽聽聽聽聽 }
聽聽聽聽聽 in.close();
聽 鎺ヤ笅鏉?灝卞彲浠ュ嫻佽繘琛屾搷浣滀簡.
聽 閭d箞,鍏充簬Javamail鐨勭爺絀朵篃灝辮繘琛屽埌榪欏効浜?
鍙傝冩枃鐚?
聽 DJ Walker-Morgan聽聽聽聽聽聽聽聽聽 Getting the mail in: receiving in JavaMail
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽Sending email in Java: There's more than one way
聽 璧靛己,涔旀柊浜犅犅犅犅犅犅犅犅犅犅犅犅犅犅犅犅犅犅燡2EE搴旂敤寮鍙?/p>