ASPAlliance.com : The #1 Active Server Pages .NET Community The #1 ASP.NET Community
Search   Search

Subscribe   Subscribe

Powered by ORCSWeb Hosting


Site Stats


Powered By ASP.NET
 
Featured Sponsor

Featured Columnist


Featured Book
XML for ASP.NET Developers
XML for ASP.NET Developers

Find Prices
Read Review
Read Review
Sample Chapter


New! asp.netPRO

We publish our articles in the standard RSS format.

Powerful .NET Email Component

Code Sharing Software
PopMail.aspx.vb by Damian Manifold
  1 public class PopMail
  2     Inherits System.Web.UI.Page
  3     protected WithEvents Srv as System.Web.UI.WebControls.TextBox
  4     protected WithEvents Passwd as System.Web.UI.WebControls.TextBox
  5     protected WithEvents Button1 as System.Web.UI.WebControls.Button
  6     protected WithEvents Answer as System.Web.UI.WebControls.Literal
  7     protected WithEvents Alliance1 as DPM.Alliance
  8     protected WithEvents Alliance2 as DPM.Alliance
  9     protected WithEvents Usr as System.Web.UI.WebControls.TextBox
  10 
  11     private Sub Page_Load(ByVal sender as System.objectByVal e as System.EventArgs) Handles MyBase.Load
  12         if Page.IsPostBack Then
  13             Dim p as new pop3(Srv.Text)
  14             Dim success as Boolean = false
  15 
  16             success = p.logon(Usr.Text, Passwd.Text)
  17             p.logoff()
  18             if success Then
  19                 Answer.Text = "Logon Successfull"
  20             else
  21                 Answer.Text = "Logon Unsuccessfull"
  22             End if
  23         End if
  24     End Sub
  25 
  26     class pop3
  27         private s as System.Net.Sockets.NetworkStream
  28         private t as new System.Net.Sockets.TcpClient()
  29         private Cnct as Boolean = false
  30 
  31         public Sub new(ByVal Server as string)
  32             'open port 110 ( the pop3 port ) On the server
  33             Try
  34                 'catch any error resuting from a bad server name
  35                 t.Connect(Server, 110)
  36                 s = t.GetStream()
  37                 'check that the connection is okay
  38                 if Left(getData(), 3) = "+OK" Then
  39                     Cnct = true
  40                 End if
  41             catch
  42             End Try
  43         End Sub
  44 
  45         public function logon(ByVal User as stringByVal passwd as stringas Boolean
  46             Dim ret as string
  47 
  48             logon = false
  49 
  50             'make sure you have a connection
  51             if Cnct Then
  52                 'send the username
  53                 ret = SendCmd("user " + User)
  54 
  55                 'if that was successfull, send the password
  56                 if Left(ret, 3) = "+OK" Then
  57                     ret = SendCmd("pass " + passwd)
  58 
  59                     'if that was successfull set the return flas to true
  60                     if Left(ret, 3) = "+OK" Then
  61                         logon = true
  62                     End if
  63                 End if
  64             End if
  65         End function
  66 
  67         public function logoff() as string
  68             if Cnct Then
  69                 logoff = SendCmd("QUIT")
  70             End if
  71         End function
  72 
  73         private function SendCmd(ByVal Cmd as stringas string
  74             Dim bCmd as byte()
  75             'byte encode the command
  76             bCmd = System.Text.Encoding.ASCII.GetBytes(Cmd + vbCrLf)
  77 
  78             'send the data
  79             s.Write(bCmd, 0, bCmd.Length)
  80             SendCmd = getData()
  81         End function
  82 
  83         private function getData() as string
  84             Dim bData(t.ReceiveBufferSize) as byte
  85             'get the response
  86             s.Read(bData, 0, bData.Length)
  87             'return the response
  88             getData = System.Text.Encoding.ASCII.GetString(bData)
  89         End function
  90     End class
  91 
  92 End class
  93 
PopMail.aspx.vbGenerated using CodeView
 Copyright © 2000-2003 ASPAlliance.com  Page Rendered at 3/20/2010 2:04:49 AM