ASP寫的JMail組件的郵件收取
當(dāng)前位置:點(diǎn)晴教程→知識(shí)管理交流
→『 技術(shù)文檔交流 』
<% response.Flush Dim EmailUserName,EmailUserPass,EmailUserPOP,IfDelete set rs=conn.execute("select * from MyDesktop_IMAccount where AccountCode='"&request("code")&"' and UserID='"&session("userid")&"'") EmailUserName=rs("Account") EmailUserPass=rs("Password") EmailUserPOP=rs("Pop3Server") IfDelete=rs("ifdelete") rs.close if EmailUserPass="" then EmailUserPass=request("password") if EmailUserPass="" then response.write "" response.end end if end if Dim POP3,J '下載并閱讀郵件。 '------------------------ Set POP3 = Server.CreateObject("JMail.POP3") POP3.Connect EmailUserName,EmailUserPass,EmailUserPOP POP3.DownloadHeaders set rs=server.createobject("adodb.recordset") rs.open "select * from MyDesktop_IM",conn,1,3,1 if pop3.count>0 then for J=1 to pop3.count Dim Subject,MSGBody,MSGHTMLBody,MSGFrom,MSGFromName,ReTo,ReCC,FileUrl,FileName,AcceptTime Subject=POP3.Messages.Item(J).Subject '郵件主題 MSGFrom=POP3.Messages.Item(J).From '發(fā)件人郵箱 MSGFromName=POP3.Messages.Item(J).FromName '發(fā)件人 Call getAttachments(J) '存儲(chǔ)附件 response.write " "&Subject rs.addnew() rs("AccountCode")=Request("code") rs("SendMail")=MSGFrom rs("SendMailName")=MSGFromName rs("AcceptMail")=ReTo rs("CopyMail")=ReCC rs("ClassCode")=1 rs("MailTitle")=Subject if MSGHTMLBody="" then rs("MailBody")=replace(MSGBody,chr(10)," ") else rs("MailBody")=MSGHTMLBody end if rs("FileUrl")=FileUrl rs("FileName")=FileName rs("SendAcceptTime")=AcceptTime rs("MailState")=1 rs.update() next end if rs.close Set Attachments=Nothing Set TheMsg=Nothing if ifdelete then POP3.DeleteMessages end if POP3.Disconnect Set POP3=Nothing endconn() Response.write "" '轉(zhuǎn)到收件箱 '---------將附件存儲(chǔ)到本地服務(wù)器------------------ Sub getAttachments(J) Dim Path,AT,separator,i,iPath,Att,POP,Re Set POP = Server.CreateObject("JMail.POP3") POP.Connect EmailUserName,EmailUserPass,EmailUserPOP MSGBody=POP.Messages.Item(J).Body '純文本內(nèi)容 MSGHTMLBody=POP.Messages.Item(J).HTMLBody '超文本內(nèi)容 MSGBody=Trim(MSGBody) MSGHTMLBody=Trim(MSGHTMLBody) AcceptTime=POP.Messages.Item(J).Date '接收時(shí)間 FileName="" FileUrl="" ReTo="" ReCC="" Set Att = POP.Messages.Item(J).Attachments separator = "," if Att.Count>0 then For i = 0 To Att.Count-1 If i = Att.Count-1 Then separator = "" End If Set AT = Att.item(i) if AT.Name<>".msg" then Path="/EMail/attachments/" & iRandom & "/" Call CreateAFolder(Server.Mappath(Path)) iPath=Server.Mappath(Path) & "\" & AT.Name AT.SaveToFile(iPath) FileUrl = FileUrl & Path & AT.Name & separator FileName = FileName & AT.Name & separator else if MSGHTMLBody="" then MSGHTMLBody=AT.data end if end if Next end if '--------------收件人------------ Set Recipients = POP.Messages.Item(J).Recipients separator = "," For i = 0 To Recipients.Count - 1 If i = Recipients.Count - 1 Then separator = "" End If Set Re = Recipients.item(i) If Re.ReType = 0 Then if ReTo<>"" then ReTo=ReTo & "," end if ReTo = ReTo & Re.EMail else if ReCC<>"" then ReCC=ReCC & "," end if ReCC = ReCC & Re.EMail End If Next Set Re=Nothing Set Recipients=Nothing '--------------------------------- Set AT=Nothing Set Att=Nothing POP.Disconnect Set POP=Nothing End Sub '--------隨機(jī)函數(shù)------------------ Function iRandom() Randomize iRandom=Session("UserID")&month(date())&day(date())&Minute(time())&Second(time)&CLng(10000 * Rnd) end Function '--------創(chuàng)建新文件夾-------------- Sub CreateAFolder(Path) Dim fso Set fso = CreateObject("Scripting.FileSystemObject") fso.CreateFolder(Path) Set fso=Nothing End Sub %> 該文章在 2010/2/1 22:56:01 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |