【发布时间】:2014-08-26 00:56:45
【问题描述】:
我在 ASP.net 4.0 中工作,该程序旨在读取来自 pop3.mail.com 服务器的电子邮件。
错误代码:
请求“System.Net.SocketPermission, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”类型的权限失败。
Pop3Client 和 OpenPop.dll 等其他电子邮件程序不适用于 ASP.net 4.0。
这个程序可能在 4.0 中工作,因为它没有附加外部 dll 程序。
代码:
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim tcpclient As New TcpClient()
tcpclient.Connect("pop3.mail.com", 995)
Dim sslstream As System.Net.Security.SslStream = New SslStream(tcpclient.GetStream())
sslstream.AuthenticateAsClient("pop3.mail.com")
Dim sw As System.IO.StreamWriter = New StreamWriter(sslstream)
Dim reader As System.IO.StreamReader = New StreamReader(sslstream)
sw.WriteLine("USER email@mail.com")
sw.Flush()
sw.WriteLine("PASS pass1")
sw.Flush()
sw.WriteLine("RETR 1")
sw.Flush()
sw.WriteLine("Quit ")
sw.Flush()
Dim str As String = String.Empty
Dim strTemp As String = String.Empty
While ((strTemp = reader.ReadLine()) <> "")
If strTemp = "." Then
Exit While
End If
If strTemp.IndexOf("-ERR") <> -1 Then
Exit While
End If
str = str & " " & strTemp
End While
TextBox1.Text = str
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub
【问题讨论】:
-
这个库对我有用github.com/smiley22/S22.Pop3