在ASP中用EasyMailObject组件处理Exchange邮件源代码---保存附件(saveatt.asp)
1@ Language=VBScript
1
2'*************************************
3
4'这个文件用来下载附件
5'作者:awayeah
6'邮箱:[email protected]
7
8'*************************************
9
10
11Dim fso, tempfile
12Set fso = CreateObject("Scripting.FileSystemObject")
13Dim tfolder, tname, tfile
14' Const TemporaryFolder = 2
15' Set tfolder = fso.GetSpecialFolder(TemporaryFolder)
16set POP3=session("pop3")
17
18' Set POP3 = CreateObject("EasyMail.POP3.5")
19' POP3.LicenseKey = "awa/S19I500R1AX30C0R3100"
20' POP3.MailServer = strServer
21' POP3.Account = session("straccount")
22' POP3.Password = session("strpassword")
23' pop3.PreferredBodyFormat=1
24' pop3.TimeOut=90
25x = POP3.Connect()
26If x <> 0 Then
27Response.Write "连接错误: " + CStr(x)
28POP3.Disconnect
29End If
30
31'设定附件存放的临时目录,要用绝对路径,这个目录应赋足够的权限给IUSR_HOST帐户,并且已经WEB共享
32pop3.TempDirectory="e:\webmail\mailatt"
33y = POP3.DownloadHeaders
34i=clng(request.querystring("msgid"))
35j=clng(request.querystring("attid"))
36msg = POP3.DownloadSingleMessage(i)
37'Set Message Object to point to that downloaded message
38Set Message = POP3.Messages(msg)
39'Message.Attachments(j).save tfolder+"/"+Message.Attachments(j).filename,1
40'Message.Attachments(j).save "c:\inetpub/\wwwroot\mailatt\"+Message.Attachments(j).filename,1
41'Response.write "file:///"+"/mailatt/"+Message.Attachments(j).filename
42pathname=Message.Attachments(j).TempFileName
43parentfolder=fso.GetParentFolderName(pathname)
44set folder=fso.GetFolder(parentfolder)
45dir_name=folder.name
46filename=fso.GetFileName(pathname)
47path="/webmail/mailatt/"+dir_name+"/"+filename
48Response.Redirect path