Jmail组件发送及收邮件的asp代码 三
|
admin
2010年7月3日 10:49
本文热度 6340
|
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]' 现在得到所有的收件人,并且存储[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]'这个程序得到附件,并且保存到服务器的硬盘上。也可以返回附件的详细连接[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] 邮件标题 | [br] <%= msg.subject %> | [br]
[br] [br] 发件人 | [br] <%= msg.fromname %> | [br]
[br] [br] 收件人 | [br] <%= reto %> | [br]
[br] [br] 抄送 | [br] <%= recc %> | [br]
[br] [br] 附件 | [br] <%= getattachments %> | [br]
[br] [br] 内容 | [br] <%= msg.body %> | [br]
[br]
[br] [br][br][br]<% end if[br][br] pop3.disconnect[br][br]%>[br]sendmail.asp:[br][br]您在访问网站时是否会在有些页面上见到这种功能---您在可以访问此网站的同时,[br]还可以查看您免费邮箱中是否有新邮件。这个功能是不是让您觉得很心动、很神秘呢?[br]下面,我就用asp来举个例子让您知道是如何实现这一功能的。[br][br]首先你可以去一些提供免费邮件服务的站点,申请一个账号然后登录。在打开邮箱时,[br]请您注意地址栏中的内容。现在以371为例,你会发现其内容通常是:[br]http://371.net/prog/login?user=fighter&pass=mypassword。[br]其中"fighter"是您的账号,"mypassword"是您的密码。这时我们可以从这里得到3个信息。[br]第1条是我们得到了处理文件的url及文件名:"http://371.net/prog/login";[br]第2条是记录您账号的变量名:user;第3条是记录您密码的变量名:pass。[br]我们知道这些信息后,就可着手写html文件和asp文件了。[br][br]'/*html源文件内容如下:*/[br]<html>[br]<head>[br]<meta name="generator" content="microsoft visual studio 6.0">[br]</head>[br]<title>city club 首页</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("请选择您的邮箱服务器!")[br]window.document.form1.selectmail.focus()[br]return false [br]}[br]if (tt.account.value=="") {[br]alert("帐号不能为空!请填写。")[br]tt.account.focus()[br]return false[br]}[br]if (tt.account.value.length<3) {[br]alert("帐号长度不能小于3位!请填写。")[br]tt.account.focus()[br]return false [br]}[br]if (tt.password.value=="") {[br]alert("密码不能为空!请填写。")[br]tt.password.focus()[br]return false [br]}[br]if (tt.password.value.length<3) {[br]alert("密码长度不能小于3位!请填写。")[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",是为了弹出新窗口来查看您的邮箱-->[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;'>香港免费电邮</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]帐号:<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源文件内容结束*/[br][br][br]'/*postoffice.asp源文件内容如下:*/[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.所有权归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所有权归city club)</title>[br]<body>[br]<%[br]dim str(3)[br]str1 =trim(request.form("selectmail")) '/*获取的邮件服务器及用户账号和密码信息*/[br]for i = 1 to 3 '/*将以上获取的信息进行分割,并赋予给数组变量*/[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) '/*邮件服务器地址及指定处理的文件名*/[br]end if [br]usernam = str(1) '/*账号变量名*/[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 '/*打开邮箱*/[br]%>[br]</body>[br]</html>[br][br]'/*postoffice.asp源文件内容结束*/[br][br]不是很难吧,呵呵。其实这个不是很难的,关键在于您能多多观察,找出其中的规律。这样我们就可以利用这些规律做很多很多有意义有趣的事了
该文章在 2010/7/3 10:49:23 编辑过