各位前輩好!
本人新學控制元件,想寫一段代碼用于下載郵箱里的附件,但是遇到幾個問題。
1郵箱中有郵件一千多封,但是下載的郵件只有43封。
2從下載的郵件里下載附件,發現部分附件的檔案名無法正常讀取,只能讀取前面一部分。
3實際上沒有重名的附件由于附件檔案名讀取錯誤誤判成重名檔案。
4部分附件的檔案拓展名丟失。
5收取大于1個附件的時候檔案名錯誤
代碼如下
Private Sub Form_load()
Dim jmail
Dim pop3 As New jmail.pop3
Dim mailMessage As New jmail.Message
Dim msg As New jmail.Messages
Dim atts As jmail.Attachments
Dim att As jmail.Attachment
Dim m, n As Integer
Set jmail = CreateObject("JMAIL.Message")
pop3.Connect "[email protected]", "password", "pop3.163.com"
pop3.DownloadMessages
'Response.Write ("You have " & pop3.Count & " mails in your mailbox!<br><br>")
Set att = New jmail.Attachment
If pop3.Count > 0 Then
For m = 1 To pop3.Count
Set atts = pop3.Messages.Item(m).Attachments
mailMessage.Charset = "GB2312"
mailMessage.Encoding = "Base64"
mailMessage.ISOEncodeHeaders = False
Dim strAttName As String
n = 0
strAttName = ""
For n = 0 To atts.Count - 1 '附件
If n <> 0 Then strAttName = strAttName & ","
Set att = atts(n)
strAttName = strAttName & att.Name
If Dir(App.Path & "\rar\" & strAttName) = "" Then '判斷檔案是否存在,如果存在就洗掉后保存
att.SaveToFile (App.Path & "\rar\" & strAttName)
Else
Kill App.Path & "\rar\" & strAttName
MsgBox "檔案存在" & n
att.SaveToFile (App.Path & "\rar\" & strAttName)
End If
Next n
Next m
Else
MsgBox "沒有郵件"
End If
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/261908.html
標籤:控件
上一篇:求助,這樣的代碼怎么寫
下一篇:vb6崩潰后,表單加載錯誤
