jmail4.1用pop3收信的例子:[br]<% set pop3 = server.createobject( "jmail.pop3" )[br] [br] 'pop3的連接用戶名,密碼,pop3地址[br] pop3.connect "username", "password", "mail.mydomain.com"[br][br] response.write( "你有" & pop3.count & " 封郵件。
" )[br][br] if pop3.count > 0 then[br]set msg = pop3.messages.item(1) [br]reto = ""[br]recc = ""[br][br]set recipients = msg.recipients[br]separator = ", "[br][br]' 現(xiàn)在得到所有的收件人,并且存儲(chǔ)[br][br]for i = 0 to recipients.count - 1[br] if i = recipients.count - 1 then[br] separator = ""[br] end if[br][br] set re = recipients.item(i)[br] if re.retype = 0 then[br] reto = reto & re.name & " (
" & re.email & ")" & separator[br] else[br] recc = reto & re.name & " (
" & re.email & ")" & separator[br] end if[br]next[br][br]'這個(gè)程序得到附件,并且保存到服務(wù)器的硬盤(pán)上。也可以返回附件的詳細(xì)連接[br]function getattachments()[br] set attachments = msg.attachments[br] separator = ", "[br][br] for i = 0 to attachments.count - 1[br] if i = attachments.count - 1 then[br] separator = ""[br] end if[br][br] set at = attachments(i)[br] at.savetofile( "c:\email\attachments\" & at.filename )[br] getattachments = getattachments & "
" &_[br] at.filename & "(" & at.size & " bytes)" & "" & separator[br] next[br]end function[br] [br]%> [br][br] [br]
[br] [br] 郵件標(biāo)題 | [br] <%= msg.subject %> | [br]
[br] [br] 發(fā)件人 | [br] <%= msg.fromname %> | [br]
[br] [br] 收件人 | [br] <%= reto %> | [br]
[br] [br] 抄送 | [br] <%= recc %> | [br]
[br] [br] 附件 | [br] <%= getattachments %> | [br]
[br] [br] 內(nèi)容 | [br] <%= msg.body %> | [br]
[br]
[br] [br][br][br]<% end if[br][br] pop3.disconnect[br][br]%>[br]sendmail.asp:[br][br]您在訪問(wèn)網(wǎng)站時(shí)是否會(huì)在有些頁(yè)面上見(jiàn)到這種功能---您在可以訪問(wèn)此網(wǎng)站的同時(shí),[br]還可以查看您免費(fèi)郵箱中是否有新郵件。這個(gè)功能是不是讓您覺(jué)得很心動(dòng)、很神秘呢?[br]下面,我就用asp來(lái)舉個(gè)例子讓您知道是如何實(shí)現(xiàn)這一功能的。[br][br]首先你可以去一些提供免費(fèi)郵件服務(wù)的站點(diǎn),申請(qǐng)一個(gè)賬號(hào)然后登錄。在打開(kāi)郵箱時(shí),[br]請(qǐng)您注意地址欄中的內(nèi)容?,F(xiàn)在以371為例,你會(huì)發(fā)現(xiàn)其內(nèi)容通常是:[br]http://371.net/prog/login?user=fighter&pass=mypassword。[br]其中"fighter"是您的賬號(hào),"mypassword"是您的密碼。這時(shí)我們可以從這里得到3個(gè)信息。[br]第1條是我們得到了處理文件的url及文件名:"http://371.net/prog/login";[br]第2條是記錄您賬號(hào)的變量名:user;第3條是記錄您密碼的變量名:pass。[br]我們知道這些信息后,就可著手寫(xiě)html文件和asp文件了。[br][br]'/*html源文件內(nèi)容如下:*/[br]<html>[br]<head>[br]<meta name="generator" content="microsoft visual studio 6.0">[br]</head>[br]<title>city club 首頁(yè)</title>[br]<style type="text/css">[br]<!--[br]td { font-size: 14px}[br]body { font-size: 14px}[br]select { font-size: 14px}[br]a {text-decoration: none; color: #003366; font-size: 14px}[br]a:hover {text-decoration: underline; color: #ff0000; font-size: 14px}[br]-->[br]</style>[br]< script language="java script ">[br]function check(tt) {[br]if (window.document.form1.selectmail.selectedindex==0) {[br]alert("請(qǐng)選擇您的郵箱服務(wù)器!")[br]window.document.form1.selectmail.focus()[br]return false [br]}[br]if (tt.account.value=="") {[br]alert("帳號(hào)不能為空!請(qǐng)?zhí)顚?xiě)。")[br]tt.account.focus()[br]return false[br]}[br]if (tt.account.value.length<3) {[br]alert("帳號(hào)長(zhǎng)度不能小于3位!請(qǐng)?zhí)顚?xiě)。")[br]tt.account.focus()[br]return false [br]}[br]if (tt.password.value=="") {[br]alert("密碼不能為空!請(qǐng)?zhí)顚?xiě)。")[br]tt.password.focus()[br]return false [br]}[br]if (tt.password.value.length<3) {[br]alert("密碼長(zhǎng)度不能小于3位!請(qǐng)?zhí)顚?xiě)。")[br]tt.password.focus()[br]return false[br]}[br]else[br]return true [br]}[br]</ script >[br]<body topmargin=12>[br]<table border=0 bgcolor=d3d3d3>[br]<td>[br]<form action="postoffice.asp" method=post onsubmit="return check(this)" name=form1 [br]target="_blank"> <!--此處用target="_blank",是為了彈出新窗口來(lái)查看您的郵箱-->[br]<select style="background-color:add8e6" name="selectmail">[br]<option name="mailsite" value="city club便民郵局" selected>city club便民郵局</option>[br]<option name='mailsite' value='990.net/prog/login?;user;pass;'>990</option>[br]<option name='mailsite' value='371.net/prog/login?;user;pass;'>371</option>[br]<option name='mailsite' value='188.net/prog/login?;user;pass;'>188</option>[br]<option name='mailsite' value='web.163.net/cgi/login?;user;pass;'>163</option>[br]<option name='mailsite' value='freemail.263.net/cgi/login?;user;pass;'>263</option>[br]<option name='mailsite' value='mail.777.net.cn/v2.0/html/mailbox.php3?;user;pass;'>777</option>[br]<option name='mailsite' value='126.com/cgi/login?;email;password;'>126</option>[br]<option name='mailsite' value='2911.net/cgi-bin/login?;username;password;'>2911</option>[br]<option name='mailsite' value='hotmail.yn.cninfo.net/prog/login?;user;pass;'>云南169</option>[br]<option name='mailsite' value='freemail.china.com/prog/login?;user;pass;'>china</option>[br]<option name='mailsite' value='freemail.hongkong.com/prog/login?;user;pass;'>香港免費(fèi)電郵</option>[br]<option name='mailsite' value='freemail.netease.com/prog/login?;user;pass;'>netease</option>[br]<option name='mailsite' value='lc3.law5.hotmail.com/cgi-bin/dologin?;login;passwd;'>hotmail</option>[br]<option name='mailsite' value='netaddress.com/tpl/door/login?;userid;passwd;'>use.net</option>[br]<option name='mailsite' value='88998.com/cgi-win/login?;username;password;'>88998.com</option>[br]<option name='mailsite' value='mail.com/mailcom/login.jhtml?;mn;pw;'>@mail.com</option> [br]</select><br>[br]帳號(hào):<input type=text name=account size=12 style="font-size:14px"><br>[br]密碼:<input type=password name=password size=12 style="font-size:14px"><br>[br]</td><tr><td align=center><input type=submit value="收信" style="font-size:14px">[br]<input type=reset value="重填" style="font-size:14px">[br]</td>[br]</form>[br]</td>[br]</table>[br]</body>[br]</html>[br]'/*html源文件內(nèi)容結(jié)束*/[br][br][br]'/*postoffice.asp源文件內(nèi)容如下:*/[br]<%@ language=vbscript %>[br]<%[br]response.buffer = true[br]'----------------------------------------------------[br]'author : peter.yu[br]'created date : 2000/3/13[br]'file name : postoffice.asp[br]'all rights reserved.所有權(quán)歸city club[br]'----------------------------------------------------[br]%>[br]<html>[br]<head>[br]<meta name="generator" content="microsoft visual studio 6.0">[br]</head>[br]<title>city club 便民郵局 (all rights reserved所有權(quán)歸city club)</title>[br]<body>[br]<%[br]dim str(3)[br]str1 =trim(request.form("selectmail")) '/*獲取的郵件服務(wù)器及用戶賬號(hào)和密碼信息*/[br]for i = 1 to 3 '/*將以上獲取的信息進(jìn)行分割,并賦予給數(shù)組變量*/[br]p = instr(1,str1,";")[br]str(i-1) = mid(str1,1,p-1)[br]str1 = mid(str1,p+1)[br]next[br]if instr(1,str(0),"http://")=0 then[br]websiteurl = "http://" & str(0)[br]else[br]websiteurl = str(0) '/*郵件服務(wù)器地址及指定處理的文件名*/[br]end if [br]usernam = str(1) '/*賬號(hào)變量名*/[br]password = str(2) '/*密碼變更名*/[br]'/*合并字符,得到諸如"http://371.net/prog/login?user=fighter&pass=mypassword的字符"*/[br]mailurl = websiteurl & usernam & "=" & trim(request.form("account")) [br]mailurl = mailurl & chr(38) & password & "=" & trim(request.form("password"))[br]response.redirect mailurl '/*打開(kāi)郵箱*/[br]%>[br]</body>[br]</html>[br][br]'/*postoffice.asp源文件內(nèi)容結(jié)束*/[br][br]不是很難吧,呵呵。其實(shí)這個(gè)不是很難的,關(guān)鍵在于您能多多觀察,找出其中的規(guī)律。這樣我們就可以利用這些規(guī)律做很多很多有意義有趣的事了
該文章在 2010/7/3 10:49:23 編輯過(guò)