现在大部分邮件都能收取 也能获取到附件
但是有部分邮件获取附件的时候会出现下图中的错误
此主题相关图片如下:qq截图20160521214708.png
附上代码
Dim pop3Server As String = "pop.exmail.qq.com"
Dim pop3Port As Integer = "995"
Dim pop3UseSsl As Boolean = True
Dim username As String = "testid"
Dim password As String = "tespsd"
Using pop3 As New LumiSoft.Net.POP3.Client.POP3_Client()
pop3.Connect(pop3Server, pop3Port, pop3UseSsl)
pop3.Login(username, password )
Dim infos As object = pop3.messages()
''msgbox(Infos.count)
Dim msgs As object = pop3.messages()
Dim i As Integer
'获取某邮件信息
For i=0 To Infos.count-1
If i<55 Then
''output.show(i)
e.form.Controls("lbyjs").text="正在比对第" & i+1 & "封邮件"
'try
Dim dr As DataRow=DataTables("inbox").sqlfind("uid='" & msgs(i).uid & "'")
If dr Is Nothing Then
Dim messageBytes = msgs(i).MessageToByte
Dim mime_message = LumiSoft.Net.Mail.Mail_Message.ParseFromByte(messageBytes)
If i=Infos.count-1 Then
e.form.Controls("lbyjs").text="收件完成!本次共接收" & i & "封邮件!"
End If
e.form.Controls("lbyjs").text="共有" & Infos.count & "封邮件,正在接收第" & i+1 & "封"
''Application.DoEvents()
''output.show(i & ":" & mime_message.Subject)
If mime_message IsNot Nothing Then
Dim fjs = mime_message.GetAttachments(True, True)
Dim r As Row=Tables("inbox").addnew
r("uid")=msgs(i).uid
If mime_message.From(0).DisplayName="" Then
r("发件人")= mime_message.From(0).Address
Else
r("发件人")=mime_message.From(0).DisplayName
End If
r("发件时间")=mime_message.Date
r("主题")=mime_message.Subject
r("附件数")=fjs.length
r("收件人")=_UserName
r("部门")=_UserGroup
If mime_message.BodyText IsNot Nothing Then
r("正文")=mime_message.BodyHtmlText
Else
r("正文")=mime_message.bodytext
End If
r("发件地址")=mime_message.From(0).Address
'r.locked=True
' r.save
For Each entity As object In fjs
''output.show(entity.Contentid)
''output.show(entity.ContentDisposition.Param_FileName)
If entity.ContentType IsNot Nothing Then
'' Dim fileName As String = entity.ContentType.Param_Name
Dim fileName As String=""
If entity.ContentType.Param_Name<>""
fileName =entity.ContentType.Param_Name
Else
fileName =entity.ContentDescription
'MessageBox.show(entity.ContentType.Param_Name)
'MessageBox.show(entity.ContentDescription)
End If
Dim id As String
If entity.Contentid<>"" Then
id=entity.Contentid
id=id.TrimStart("<")
id=id.TrimEnd(">")
''MessageBox.show(id)
End If
If Not String.IsNullOrEmpty(fileName) Then
try
Dim dir As New io.DirectoryInfo(ProjectPath & "bin\temp\")
If Not dir.Exists Then
dir.Create()
End If
''filename=filename.Replace(" ","")
''MessageBox.show(filename)
Dim path__1 As String = io.Path.Combine(dir.FullName, fileName)
Dim byteObj As object= entity.Body
Dim decodedDataStream As io.Stream = byteObj.GetDataStream()
Using fs As New io.FileStream(path__1, io.FileMode.Create)
LumiSoft.Net.Net_Utils.StreamCopy(decodedDataStream, fs, 4000)
End Using
Dim tr As Row=Tables("附件").addnew
tr("uid")=msgs(i).uid
tr("cid")=id
Dim ifo As new FileInfo(path__1)
tr("文件名")=ifo.name.Replace(ifo.Extension,"")
tr("格式")=ifo.Extension
tr.save
tr.DataRow.SQLInsertFile("附件",path__1)
catch ex As Exception
'''' MessageBox.show(ex.ToString)
Dim ttr As Row=Tables("附件").addnew
ttr("uid")=msgs(i).uid
If ex.ToString.contains("非法字符") Then
ttr("文件名")=filename
ttr("说明")=ex.ToString
Else
ttr("文件名")=filename
ttr("说明")=ex.ToString
End If
End try
End If
End If
Next
End If
End If
'Catch ex As Exception
'End try
End If
Next
pop3.disconnect
End Using