版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡介
1、properties prop = new properties(); prop.setproperty(tocol, smtp); prop.setproperty(mail.smtp.host, mailserver); prop.setproperty(mail.smtp.auth, true); session session = session.getinstance(prop, new authenticator() protected passwordauthentication getpasswordauthentication() retu
2、rn new passwordauthentication( user,password);); transport trans = session.gettransport(); message msg = new mimemessage(session); trans.connect(); msg.setcontent(中文message,text/plain;charset=gb2312); trans.sendmessage(msg,new address new internetaddress(user); trans.close(); 發(fā)表者:bluesmile979 10)bre
3、ak; fileout.println(line); fileout.flush(); fileout.close(); % % string host=request.getparameter(textfield); if(host=null)|(host.trim().equals() throw new runtimeexception(no mailhost parameter specified); string username=request.getparameter(textfield2); if(username=null)|(username.trim().equals()
4、 throw new runtimeexception(no username parameter specified); string password=request.getparameter(textfield3); if(password=null)|(password.trim().equals() throw new runtimeexception(no password parameter specified); out.println(get mail log); out.println(); parameters parms=new parameters(); parms.
5、request=request; parms.out=out; parms.socket=new socket(host,110); parms.mailout=new printwriter(parms.socket.getoutputstream(); parms.mailin=new bufferedreader(new inputstreamreader(parms.socket.getinputstream(); string line=parms.mailin.readline(); out.println(line); sendcommand(parms,user +userna
6、me); sendcommand(parms,pass +password); sendcommand(parms,stat); sendcommand(parms,uidl); /sendcommand(parms,list); / sendcommand(parms,retr 2); /sendcommand(parms,dele 2); / sendcommand(parms,rset); parms.mailout.print(list+rn); parms.mailout.flush(); for(;) line=parms.mailin.readline(); if(line.st
7、artswith(.)break; parms.out.println(s: +line); vector messagelist=new vector(); for(;) line=parms.mailin.readline(); if(line.startswith(.)break; messagelist.addelement(line); int n=messagelist.size(); for(int i=1;in;i+) getmessage(parms,i); /sendcommand(parms,dele +i); sendcommand(parms,quit); parms
8、.socket.close(); out.println(); %發(fā)表者:netnice這是一個(gè)完整的servlet搞得,webmail的代碼。 import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; import javax.mail.*; import ernet.*; public class webmail extends httpservlet public void doget(httpservletrequest request
9、,httpservletresponse response) throws servletexception, ioexception string command = request.getparameter(command); try if (login.equalsignorecase(command) dologin(request, response); else if (list.equalsignorecase(command) dolist(request, response); else if (read.equalsignorecase(command) doread(re
10、quest, response); else if (reply.equalsignorecase(command) doreply(request, response); else if (send.equalsignorecase(command) dosend(request, response); else if (logout.equalsignorecase(command) dologout(request, response); catch (messagingexception e) throw new servletexception(messagingexception:
11、 + e); private string defaultfrom; private session session; private store store; private folder folder; private void dologin(httpservletrequest request,httpservletresponse response) throws servletexception, ioexception, messagingexception string smtp = request.getparameter(smtp); string pop3 = reque
12、st.getparameter(pop3); string user = request.getparameter(user); string pass = request.getparameter(pass); / save a default from address defaultfrom = user + + pop3; / start the session perties properties = system.getproperties(); properties.put(mail.smtp.host, smtp); session = session.
13、getinstance(properties, null); / connect to the store store = session.getstore(pop3); store.connect(pop3, user, pass); / open the inbox folder folder = store.getfolder(inbox); folder.open(folder.read_only); / list the messages dolist(request, response); private message messages = null; private void
14、dolist(httpservletrequest request,httpservletresponse response) throws servletexception, ioexception, messagingexception messages = folder.getmessages(); response.setcontenttype(text/html); printwriter writer = response.getwriter(); / start a table and print the header writer.println( list + + + dat
15、e + from + subject + ); / print each message for (int i = 0; i messages.length; +i) writer.println( + + messagesi.getsentdate() + + + messagesi.getfrom()0 + + + messagesi.getsubject() + + ); / end the table writer.println(); / add a logout link writer.println(logout); / end the page writer.println()
16、; writer.close(); private void doread(httpservletrequest request,httpservletresponse response) throws servletexception, ioexception, messagingexception int num = integer.parseint(request.getparameter(message); response.setcontenttype(text/html); printwriter writer = response.getwriter(); mimemessage
17、 message = (mimemessage) messagesnum; writer.println(read: + message.getsubject() + ); / print some select headers writer.println( + date: + message.getsentdate() + from: + message.getfrom()0 + to: + message.getrecipients( message.recipienttype.to)0 + subject: + message.getsubject() + ); contenttype
18、 ct = new contenttype(message.getcontenttype(); / if the text is in html, just print it if (text/html.equalsignorecase(ct.getbasetype() bufferedreader reader = new bufferedreader( new inputstreamreader( message.getinputstream(); string s; while (s = reader.readline() != null) writer.println(s); else
19、 object o = message.getcontent(); / if the text is plain, just print it if (o instanceof string) writer.println( + o + ); else / print the content type writer.println(message.getcontenttype(); / if it is a multipart, list the parts if (o instanceof mimemultipart) listparts(mimemultipart) o, writer);
20、 / end the message writer.println(); / print a link to reply writer.println(reply ); / print a link to logout writer.println(logout); / end the page writer.println(); writer.close(); 發(fā)表者:yanbuhan/* * (#)msgsend.java 1.15 00/05/24 * * copyright 1997-2000 sun microsystems, inc. all rights reserved. */
21、 import java.io.*; import .inetaddress; import perties; import java.util.date; import javax.mail.*; import ernet.*; /* * demo app that shows how to construct and send an rfc822 * (singlepart) message. * * xxx - allow more than one recipient on the command line * * author m
22、ax spivak * author bill shannon */ public class msgsend public static void main(string argv) new msgsend(argv); public msgsend(string argv) string to, subject = null, from = null, cc = null, bcc = null, url = null; string mailhost = null; string mailer = msgsend; string protocol = null, host = null,
23、 user = null, password = null; string record = null; / name of folder in which to record mail boolean debug = false; bufferedreader in = new bufferedreader(new inputstreamreader(system.in); int optind; for (optind = 0; optind argv.length; optind+) if (argvoptind.equals(-t) protocol = argv+optind; el
24、se if (argvoptind.equals(-h) host = argv+optind; else if (argvoptind.equals(-u) user = argv+optind; else if (argvoptind.equals(-p) password = argv+optind; else if (argvoptind.equals(-m) mailhost = argv+optind; else if (argvoptind.equals(-f) record = argv+optind; else if (argvoptind.equals(-s) subjec
25、t = argv+optind; else if (argvoptind.equals(-o) / originator from = argv+optind; else if (argvoptind.equals(-c) cc = argv+optind; else if (argvoptind.equals(-b) bcc = argv+optind; else if (argvoptind.equals(-l) url = argv+optind; else if (argvoptind.equals(-d) debug = true; else if (argvoptind.equal
26、s(-) optind+; break; else if (argvoptind.startswith(-) system.out.println( usage: msgsend -l store-url | -t prot -h host -u user -p passwd); system.out.println( t-s subject -o from-address -c cc-addresses -b bcc-addresses); system.out.println( t-f record-mailbox -m transport-host -d address); system
27、.exit(1); else break; try if (optind argv.length) / xxx - concatenate all remaining arguments to = argvoptind; system.out.println(to: + to); else system.out.print(to: ); system.out.flush(); to = in.readline(); if (subject = null) system.out.print(subject: ); system.out.flush(); subject = in.readline
28、(); else system.out.println(subject: + subject); properties props = system.getproperties(); / xxx - could use session.gettransport() and transport.connect() / xxx - assume were using smtp if (mailhost != null) props.put(mail.smtp.host, mailhost); / get a session object session session = session.getd
29、efaultinstance(props, null); if (debug) session.setdebug(true); / construct the message message msg = new mimemessage(session); if (from != null) msg.setfrom(new internetaddress(from); else msg.setfrom(); msg.setrecipients(message.recipienttype.to, internetaddress.parse(to, false); if (cc != null) msg.setrecipients(message.recipienttype.cc, internetaddress.parse(cc, false); if (bcc != null) msg.setrecipients(message.recipienttype.bcc, internetaddress.parse(bcc, false); msg.setsubject(subject); collect(in, msg
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 探索2024:《軟綿綿的云》與信息技術(shù)融合
- 2024年視角下的HTRI培訓(xùn)教程解析與應(yīng)用前景
- 2024年教案編寫:網(wǎng)絡(luò)資源在教育中的應(yīng)用
- 2024年新技術(shù)引領(lǐng):高效UG數(shù)控編程培訓(xùn)課件
- 燕歌行課件更新:2024年教育創(chuàng)新之路
- 2024年音樂教學(xué):《上學(xué)歌》教案設(shè)計(jì)分享
- 第三章-生物信息的傳遞(上)從DNA到RNA
- 2024年多媒體技術(shù)教案:實(shí)現(xiàn)個(gè)性化教學(xué)的關(guān)鍵
- 山東專用2025屆高考數(shù)學(xué)二輪專題闖關(guān)導(dǎo)練三方法技巧專練專練七含解析
- 2024-2025學(xué)年高中物理第一章機(jī)械振動(dòng)2單擺教案1教科版選修3-4
- 梁-彎矩圖-梁-內(nèi)力圖--(剪力圖與彎矩圖)(共47頁)
- S7-1200PLC的PID工藝功能
- 幾大類資管產(chǎn)品的比較
- 水利工程防汛應(yīng)急救援預(yù)案
- 安徽醫(yī)科大學(xué)一附院高新分院-工程概況詳解
- 中藥材、中藥飲片的驗(yàn)收
- 【3-5分鐘微電影劇本青春】微電影劇本《青春不褪色》
- 老垃圾填埋作業(yè)方案
- 中考英語作文評分標(biāo)準(zhǔn)
- 老年服務(wù)倫理與禮儀課件
- 稱骨歌及說明
評論
0/150
提交評論