用jamil接收附件的问题。求助。

avonlinu 2002-07-27 11:43:26

邮件的附件保存到本机出错:
at.SaveToFile( "c:\temp\" & at.Name ),是什么问题?

另外:如何捕获连接pop3 server时的错误?即pop3.Connect "liming", "liming", "172.16.1.6"
出错时如何捕获?

请教各位。

代码如下:
<% @LANGUAGE=VBSCRIPT %>
<%

'*************************************************
'* *
'* Produced by Dimac *
'* *
'* More examples can be found at *
'* http://tech.dimac.net *
'* *
'* Support is available at our helpdesk *
'* http://support.dimac.net *
'* *
'* Our main website is located at *
'* http://www.dimac.net *
'* *
'*************************************************




Set pop3 = Server.CreateObject( "JMail.POP3" )

pop3.Connect "liming", "liming", "172.16.1.6"

Response.Write( "You have " & pop3.count & " mails in your mailbox!<br><br>" )

if pop3.count > 0 then
Set msg = pop3.Messages.item(1) ' Note the first element of this array is 1
' since the POP3 server starts counting at 1
ReTo = ""
ReCC = ""

Set Recipients = msg.Recipients
separator = ", "

' We now need to get all the recipients,
' both normal and Carbon Copy (CC) recipients
' and store them in a variabel

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
ReTo = ReTo & re.Name & " (<a href=""mailto:"& re.EMail &""">" & re.EMail & "</a>)" & separator
else
ReCC = ReTo & re.Name & " (<a href=""mailto:"& re.EMail &""">" & re.EMail & "</a>)" & separator
End If
Next

' This function iterates through the Attachments object,
' and saves the attachment to the server's disk.
' It also returns a nicely formatted string with a
' link to the attachment.
Function getAttachments()
Set Attachments = msg.Attachments
separator = ", "

For i = 0 To Attachments.Count - 1
If i = Attachments.Count - 1 Then
separator = ""
End If

Set at = Attachments(i)
'***********************************************************************
at.SaveToFile( "c:\temp\" & at.Name )
'***********************************************************************
getAttachments = getAttachments & "<a href=""/temp" & at.Name &""">" &_
at.Name & "(" & at.Size & " bytes)" & "</a>" & separator
Next
End Function

%>
<html>
<body>
<TABLE>
<tr>
<td>Subject</td>
<td><%= msg.Subject %></td>
</tr>
<tr>
<td>From</td>
<td><%= msg.FromName %></td>
</tr>
<tr>
<td>Recipients To</td>
<td><%= ReTO %></td>
</tr>
<tr>
<td>Recipients CC</td>
<td><%= ReCC %></td>
</tr>
<tr>
<td>Attachments</td>
<td><%= getAttachments %></td>
</tr>
<tr>
<td>Body</td>
<td><pre><%= msg.Body %></pre></td>
</tr>
</TABLE>
</body>
</html>
<%

end if

pop3.Disconnect

%>
...全文
27 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
avonlinu 2002-07-27
  • 打赏
  • 举报
回复
<% Set pop3 = Server.CreateObject( "JMail.POP3" )

'pop3的连接用户名,密码,pop3地址
pop3.Connect "username", "password", "mail.mydomain.com"

Response.Write( "你有" & pop3.count & " 封邮件。<br><br>" )

if pop3.count > 0 then
Set msg = pop3.Messages.item(1)
ReTo = ""
ReCC = ""

Set Recipients = msg.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
ReTo = ReTo & re.Name & " (<a href=""mailto:"& re.EMail &""">" & re.EMail & "</a>)" &
separator
else
ReCC = ReTo & re.Name & " (<a href=""mailto:"& re.EMail &""">" & re.EMail & "</a>)" &
separator
End If
Next

'这个程序得到附件,并且保存到服务器的硬盘上。也可以返回附件的详细连接
Function getAttachments()
Set Attachments = msg.Attachments
separator = ", "

For i = 0 To Attachments.Count - 1
If i = Attachments.Count - 1 Then
separator = ""
End If

Set at = Attachments(i)
at.SaveToFile( "c:\EMail\attachments\" & at.Filename )
getAttachments = getAttachments & "<a href=""/EMail/attachments/" & at.Filename &""">" &_
at.FileName & "(" & at.Size & " bytes)" & "</a>" & separator
Next
End Function

%>
<html>
<body>
<TABLE>
<tr>
<td>邮件标题</td>
<td><%= msg.Subject %></td>
</tr>
<tr>
<td>发件人</td>
<td><%= msg.FromName %></td>
</tr>
<tr>
<td>收件人</td>
<td><%= ReTO %></td>
</tr>
<tr>
<td>抄送</td>
<td><%= ReCC %></td>
</tr>
<tr>
<td>附件</td>
<td><%= getAttachments %></td>
</tr>
<tr>
<td>内容</td>
<td><pre><%= msg.Body %></pre></td>
</tr>
</TABLE>
</body>
</html>

<% end if

pop3.Disconnect

%>
pine460 2002-07-27
  • 打赏
  • 举报
回复
可以注释一下吗?
avonlinu 2002-07-27
  • 打赏
  • 举报
回复
帮我

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧