<p> 3) 发送邮件</p><p> <img src="/content/uploadfile/200805/2008053117030203.jpg" onclick="get_larger(this)" title="请点击图片查看原图" /></p><p> 图五</p><p> 发送邮件功能的实现主要采用了Jmail.Message对象完成,关于所要用到的对象相关知识在前面已经叙述过了,大家可以将上面的功能介绍与源码对照起来阅读,这样有助于理解整个邮件发送过程,当然如果将WM元素换为HTMLF元素,这样一个简单的WEB邮件发送功能也就完成了,send.asp为邮件发送页面 sendok.asp为邮件发送处理页面</p><p> Send.asp</p><code> 〈% @LANGUAGE="VBSCRIPT" CODEPAGE="65001" %〉<br /> 〈%Response.ContentType = "text/vnd.wap.wml; charset=UTF-8"%〉<br /> 〈?xml version="1.0" encoding="utf-8"?〉<br /> 〈!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"〉<br /> 〈wml〉<br /> 〈card id="main" title="发件箱"〉<br /> 〈p〉<br /> 〈%<br /> user=request("user")<br /> pwd=request("pwd")<br /> %〉<br /> 收件人:<br /> 〈input type="text" title="收件人" name="tomail" size="12" maxlength="50"/〉〈br/〉<br /> 标题:<br /> 〈input type="text" title="标题" name="subject" size="12" maxlength="50"/〉<br /> 〈br/〉内容:<br /> 〈input type="text" title="内容" name="body" size="12" maxlength="250"/〉〈br/〉<br /> 〈do type="accept" label="发送" optional="false"〉<br /> 〈go href="sendok.asp?user=〈%=user%〉&pwd=〈%=pwd%〉" method="post" accept-charset="utf-8"〉<br /> 〈postfield name="from" value="$(from)"/〉<br /> 〈postfield name="tomail" value="$(tomail)"/〉<br /> 〈postfield name="subject" value="$(subject)"/〉<br /> 〈postfield name="body" value="$(body)"/〉〈/go〉<br /> 〈/do〉<br /> 〈/p〉<br /> 〈p〉<br /> 〈a href="main.asp?user=〈%=user%〉&pwd=〈%=pwd%〉"〉返回邮箱〈/a〉〈/p〉<br /> 〈/card〉<br /> 〈/wml〉</code><p> Sendok.asp</p>
<p> </p>
<code> 〈% @LANGUAGE="VBSCRIPT" CODEPAGE="65001" %〉<br /> 〈%Response.ContentType = "text/vnd.wap.wml; charset=UTF-8"%〉<br /> 〈?xml version="1.0" encoding="utf-8"?〉<br /> 〈!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"〉<br /> 〈wml〉<br /> 〈card id="main" title="发送邮件"〉<br /> 〈p〉<br /> 〈%<br /> user=request("user")<br /> pwd=request("pwd")<br /> tomail=request("tomail")<br /> 'from=request.form("from")<br /> subject=request.form("subject")<br /> body=request.form("body")<br /> servermail=user+"@sohu.com"<br /> dim JMail<br /> set JMail=server.CreateObject("Jmail.message")<br /> JMail.Silent=true<br /> JMail.Charset = "gb2312"<br /> JMail.from =""&ServerMail&"" '为发件人<br /> JMail.AddRecipient tomail<br /> JMail.Subject =""&subject&""<br /> jmail.Body=""&body&"----------你当前使用的众赢掌中邮系统,详情请访问:http://www.palmmail.cn邮通天下 一触即发!----------"<br /> JMail.MailServerUserName =user<br /> JMail.MailServerPassWord = pwd<br /> JMail.MailDomain = "www.sohu.com"<br /> JMail.Priority=2<br /> sendok=JMail.send("smtp.sohu.com")<br /> Set JMail=nothing<br /> if sendok then<br /> response.write "发送成功!〈a href='main.asp?user="&user&"&pwd="&pwd&"'〉返回邮箱〈/a〉"<br /> else<br /> response.write "发送失败!〈a href='send.asp?user="&user&"&pwd="&pwd&"'〉返回邮箱〈/a〉"<br /> end if<br /> %〉<br /> 〈/p〉<br /> 〈/card〉<br /> 〈/wml〉</code><p> 4) 接收邮件</p>
<p> </p>
<p> <img src="/content/uploadfile/200805/2008053117030324.jpg" onclick="get_larger(this)" title="请点击图片查看原图" /></p><p> 图六</p><p> 接收邮件主要由两部分组成,第一部分为邮件列表,根据所获得的邮件总数(pop3.count)进行分页显示。第二部分为每封信的具体内容,其中包括对附件进行检测功能,由于手机浏览时并不能打开附件,因此本系统只对附件作了检测并提醒用户邮件是否包含邮件功能。</p><p> 源码如下:</p><p> 邮件列表:email_list.asp</p><code> 〈% @LANGUAGE="VBSCRIPT" CODEPAGE="65001" %〉<br /> 〈%Response.ContentType = "text/vnd.wap.wml; charset=UTF-8"%〉<br /> 〈?xml version="1.0" encoding="utf-8"?〉<br /> 〈!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"〉<br /> 〈wml〉<br /> 〈card id="main" title="收件箱"〉<br /> 〈p〉<br /> 〈%<br /> user=request("user")<br /> pwd=request("pwd")<br /> dim perpage_num,curpage,totalpage<br /> perpage_num=3 '设每页显示条数<br /> if request("page")="" then<br /> curpage=1 '当前页<br /> else<br /> curpage=int(request("page"))<br /> end if<br /> Set pop3 = Server.CreateObject( "JMail.POP3" )<br /> pop3.connect user,pwd,"http://pop3.sohu.com"<br /> ' POP3的连接用户名,密码,POP3地址<br /> if pop3.count mod perpage_num〈〉0 then<br /> totalpage=int(pop3.count / perpage_num)+1<br /> else<br /> totalpage=int(pop3.count / perpage_num)<br /> end if<br /> Response.Write( "你现在有" & pop3.count & " 封邮件。分"&totalpage&"页,当前"&curpage&"页〈br/〉---------------------〈br/〉" )<br /> if pop3.count 〉 0 then '如果没有邮件则显示无邮件<br /> if pop3.count〉=perpage_num*curpage then<br /> for i=(curpage-1)*perpage_num to curpage*perpage_num-1%〉<br /> 〈a href="email_info.asp?id=〈%=i+1%〉&user=〈%=user%〉&pwd=〈%=pwd%〉&page=〈%=curpage%〉"〉〈%=pop3.messages.item(i+1).Subject%〉--〈%=pop3.messages.item(i+1).date%〉〈/a〉〈br/〉<br /> 〈%next<br /> %〉<br /> 〈%if curpage〉1 then%〉<br /> 〈a href="email_list.asp?page=〈%=curpage-1%〉&user=〈%=user%〉&pwd=〈%=pwd%〉"〉上一页〈/a〉<br /> 〈%end if%〉<br /> 〈%if int(curpage)〈int(totalpage) then%〉<br /> 〈a href="email_list.asp?page=〈%=curpage+1%〉&user=〈%=user%〉&pwd=〈%=pwd%〉"〉下一页〈/a〉<br /> 〈%end if%〉<br /> 〈%<br /> else<br /> for i=(curpage-1)*perpage_num to pop3.count-1%〉<br /> 〈a href="email_info.asp?id=〈%=i+1%〉&user=〈%=user%〉&pwd=〈%=pwd%〉&page=〈%=curpage%〉"〉〈%=pop3.messages.item(i+1).Subject%〉--〈%=pop3.messages.item(i+1).date%〉〈/a〉〈br/〉<br /> 〈%next%〉<br /> 〈%if curpage〉1 then%〉<br /> 〈a href="email_list.asp?page=〈%=curpage-1%〉&user=〈%=user%〉&pwd=〈%=pwd%〉"〉上一页〈/a〉<br /> 〈%end if%〉<br /> 〈%if int(curpage)〈int(totalpage) then%〉<br /> 〈a href="email_list.asp?page=〈%=curpage+1%〉&user=〈%=user%〉&pwd=〈%=pwd%〉"〉下一页〈/a〉<br /> 〈%end if%〉<br /> 〈%<br /> end if<br /> else<br /> response.write("暂无邮件!")<br /> end if<br /> pop3.Disconnect<br /> %〉<br /> 〈/p〉<br /> 〈p〉<br /> 〈a href="main.asp?user=〈%=user%〉&pwd=〈%=pwd%〉"〉返回邮箱〈/a〉<br /> 〈/p〉<br /> 〈/card〉<br /> 〈/wml〉</code><p> 邮件详细信息:email_info.asp</p>
<p> </p>
<code> 〈% @LANGUAGE="VBSCRIPT" CODEPAGE="65001" %〉<br /> 〈%Response.ContentType = "text/vnd.wap.wml; charset=UTF-8"%〉<br /> 〈?xml version="1.0" encoding="utf-8"?〉<br /> 〈!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"〉<br /> 〈wml〉<br /> 〈card id="main" title="查看邮件"〉<br /> 〈p〉<br /> 〈%<br /> user=request("user")<br /> pwd=request("pwd")<br /> id=request("id")<br /> page=request("page")<br /> Set pop3 = Server.CreateObject( "JMail.POP3" )<br /> ' POP3的连接用户名,密码,POP3地址<br /> pop3.connect user,pwd,"http://pop3.sohu.com"<br /> Set msg = pop3.Messages.item(id)<br /> ReTo = ""<br /> ReCC = ""<br /> Set Recipients = msg.Recipients<br /> separator = ", "<br /> For i = 0 To Recipients.Count - 1<br /> If i = Recipients.Count - 1 Then<br /> separator = ""<br /> End If<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 /> body=msg.body<br /> body=replace(body,"〈","")<br /> body=replace(body,"〉","")<br /> Set Attachments = msg.Attachments<br /> %〉<br /> 〈a href="email_title.asp?user=〈%=user%〉&pwd=〈%=pwd%〉&page=〈%=page%〉"〉返回上一页〈/a〉 〈a href="reply.asp?user=〈%=user%〉&pwd=〈%=pwd%〉&mailto=〈%=msg.From%〉"〉回复〈/a〉 〈a href="email_del.asp?user=〈%=user%〉&pwd=〈%=pwd%〉&id=〈%=id%〉"〉删除〈/a〉<br /> 〈/p〉<br /> 〈p〉<br /> 发件人:〈%= msg.FromName %〉--〈%=msg.date%〉〈br/〉<br /> 标题:〈%= msg.Subject %〉〈br/〉<br /> 内容:〈%= body %〉〈br/〉<br /> 〈%<br /> if Attachments.Count〉0 then<br /> response.Write("信件中包含附件,请通过网络查收!")<br /> end if<br /> pop3.Disconnect<br /> %〉<br /> 〈/p〉<br /> 〈p〉<br /> 〈a href="email_list.asp?user=〈%=user%〉&pwd=〈%=pwd%〉&page=〈%=page%〉"〉返回上一页〈/a〉 〈a href="reply.asp?user=〈%=user%〉&pwd=〈%=pwd%〉&mailto=〈%=msg.From%〉"〉回复〈/a〉 〈a href="email_del.asp?user=〈%=user%〉&pwd=〈%=pwd%〉&id=〈%=id%〉"〉删除〈/a〉<br /> 〈/p〉<br /> 〈/card〉<br /> 〈/wml〉</code><p> 5) 删除邮件</p>
<p> </p>
<p> 本功能与邮件回复功能一样,为邮件查看页面的一个子功能,通过MessageID传递实现删除邮件。</p><p> 源码:email_del.asp</p><code> 〈% @LANGUAGE="VBSCRIPT" CODEPAGE="65001" %〉<br /> 〈%Response.ContentType = "text/vnd.wap.wml; charset=UTF-8"%〉<br /> 〈?xml version="1.0" encoding="utf-8"?〉<br /> 〈!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"〉<br /> 〈wml〉<br /> 〈card id="main" title="删除成功"〉<br /> 〈p〉<br /> 〈%<br /> user=request("user")<br /> pwd=request("pwd")<br /> id=request("id")<br /> Set pop3 = Server.CreateObject( "JMail.POP3" )<br /> ' POP3的连接用户名,密码,POP3地址<br /> pop3.connect user,pwd,"http://pop3.sohu.com"<br /> pop3.deletesinglemessage id<br /> pop3.Disconnect<br /> Set JMail=nothing<br /> response.write delok&"删除成功!〈a href='email_list.asp?user="&user&"&pwd="&pwd&"'〉返回收件箱〈/a〉"<br /> %〉<br /> 〈/p〉<br /> 〈/card〉<br /> 〈/wml〉</code><p> 6) 回复邮件</p><p> 回复邮件基本与发送邮件相同,只是将发送人由原来的手工输入改成通过URL参数传递,当然也可以将邮件主体内容传递到回复邮件的主体中,但由于当今手机上网基本采用流量收费的方式,为了减少流量就省去了这些功能,具体代码如下:</p>
<p> </p>
<p> Reply.asp</p><code> 〈% @LANGUAGE="VBSCRIPT" CODEPAGE="65001" %〉<br /> 〈%Response.ContentType = "text/vnd.wap.wml; charset=UTF-8"%〉<br /> 〈?xml version="1.0" encoding="utf-8"?〉<br /> 〈!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"〉<br /> 〈wml〉<br /> 〈card id="main" title="发件箱"〉<br /> 〈p〉<br /> 〈%<br /> user=request("user")<br /> pwd=request("pwd")<br /> tomail=request("mailto")<br /> %〉<br /> 收件人:<br /> 〈%=tomail%〉〈br/〉<br /> 标题:<br /> 〈input type="text" title="标题" name="subject" size="8" maxlength="50"/〉<br /> 〈br/〉内容:<br /> 〈input type="text" title="内容" name="body" size="8" maxlength="250"/〉〈br/〉<br /> 〈do type="accept" label="发送" optional="false"〉<br /> 〈go href="sendok.asp?user=〈%=user%〉&pwd=〈%=pwd%〉&tomail=〈%=tomail%〉" method="post" accept-charset="utf-8"〉<br /> 〈postfield name="subject" value="$(subject)"/〉<br /> 〈postfield name="body" value="$(body)"/〉〈/go〉<br /> 〈/do〉<br /> 〈/p〉<br /> 〈p〉<br /> 〈a href="email_list.asp?user=〈%=user%〉&pwd=〈%=pwd%〉"〉返回收件箱〈/a〉〈br/〉<br /> 〈a href="main.asp?user=〈%=user%〉&pwd=〈%=pwd%〉"〉返回邮箱〈/a〉〈/p〉<br /> 〈/card〉<br /> 〈/wml〉</code><p> 虽然这套系统可以实现邮件的发送、接收、回复、删除等功能,但是很多方面都是非常欠缺的,比如接收邮件时不能够显示出未读邮件,邮件不能够按照发送邮件的先后顺序排序等等,希望大家有兴趣帮忙多多完善,有什么好的想法好的建议多与我交流,欢迎来信sn1985boy@sohu.com。</p>