Test the message on the POP3 mail server (VB.NET)

xiaoxiao2021-03-06  17

'************************************************************' Check Mail Example 'Author: wgscd' qq 153964481 '*********** ************* Imports System.Netimports System.Net. Socketsimports System.io

Public class form1 inherits system.windows.Forms.form

#Region "Windows Form Designer Generated Code"

Public Sub new () mybase.new ()

'This call is required for the Windows Form Designer. InitializeComponent ()

'Add any initialization after INITIALIZECOMPONENT ()

End Sub

'Form rewriting Dispose to clean up the list of components. Protected overloads overrides sub dispose (byval disposing as boolean) ing disponation kiln (Components Is Nothing) Then components.dispose () end if endiffs) End sub

'Windows Form Designer Supply Private Components as System.comPonentModel.icontainer

'Note: The following procedure is necessary to use the Windows Form Designer to modify this process using the Windows Form Designer. 'Don't modify it using the code editor.

Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents Timer1 As System.Windows.Forms.Timer Friend WithEvents ListBox1 As System.Windows.Forms.ListBox Private Sub InitializeComponent () Me.components = New System.ComponentModel.Container Me.Button1 = New System.Windows.Forms.Button Me.Timer1 = New System.Windows.Forms.Timer (Me.components) Me.ListBox1 = New System.Windows.Forms.ListBox Me. SuspendLayout () '' Button1 'me.button1.backcolor = system.drawing.color.fromargb (ctype (192, byte), ctype (192, byte), ctype (255, byte) me.button1.flatstyle = system. Windows.Forms.Flatstyle.Flat Me.Button1.Location = new system.drawing.point (16, 8) me.button1.name = "button1" me.button1.size = new system.drawing.size (104, 40) Me.button1.tabindex = 0 me.button1.text = "Checkmai" '' Timer1 'me.timer1.in TERVAL = 2000 '' ListBox1 'me.listbox1.backcolor = system.drawing.color.fromargb (ctype (255, byte), ctype (255, byte), ctype (192, byte) me.listbox1.horizontalscrollbar = true me .Listbox1.draw1.location = new system.drawing.point (16, 64) me.listbox1.name = "listbox1" me.listbox1.size = new system.drawing.size (104, 100) ME .Listbox1.tabindex = 2 '' form1 'me.autoscalebasesize = new system.drawing.size (6, 14) me.backcolor =

System.drawing.color.fromargb (ctype (192, byte), ctype (192, byte), ctype (255, byte) me.drawing.size (146, 182) Me.Controls.add ( Me.ListBox1) Me.controls.add (me.button1) me.formborderstyle = system.windows.forms.formorderstyle.fixedToolWindow me.name = "form1" me.text = "msg ------ by wgscd" ME .ResumeLayout (false) End Sub

#End region

Sub checkMail () Dim ip As IPAddress = Dns.GetHostByName (Dns.GetHostName.ToString) .AddressList (0) Dim ipe As New IPEndPoint (ip, 2345) Me.Text = ip.ToString Dim tcpc As New TcpClient (ipe) tcpc .Connect (Dns.GetHostByName ( "pop3.126.com"). HostName, 110) Dim ntstream As NetworkStream Dim sr As StreamReader Dim sw As StreamWriter ntstream = tcpc.GetStream Me.ListBox1.Items.Add (ReadFromNetStream (ntstream)) WriteToNetStream (ntstream, "user wgscd") Me.ListBox1.Items.Add (ReadFromNetStream (ntstream)) WriteToNetStream (ntstream, "pass yourpassword") Dim msg As String = ReadFromNetStream (ntstream) If msg Like " OK 0 message *" Then MsgBox ( "No Mail Right now!") Me.ListBox1.Items.Add (ReadFromNetStream (ntstream)) Else MsgBox (msg) WriteToNetStream (ntstream, "list") Me.ListBox1.Items.Add (ReadFromNetStream (ntstream)) END IF WRI TetonetStream (NTSTREAM, "Quit") me.listbox1.items.add (ReadFromnetStream (NtStream) TCPC.Close () end SUB

Function ReadFromNetStream (ByRef NetStream As NetworkStream) As String Dim bb As Byte () = New Byte (521) {} NetStream.Read (bb, 0, bb.Length) Dim read As String = System.Text.Encoding.UTF8.GetString (bb) Return read End Function Function WriteToNetStream (ByRef NetStream As NetworkStream, ByVal command As String) As String Dim stringToSend As String = command & vbCrLf Dim arrayToSend As Byte () = System.Text.Encoding.UTF8.GetBytes (stringToSend.ToCharArray ) NetStream.Write (arrayToSend, 0, arrayToSend.Length) 'written to the stream, do not return values ​​End FunctionPrivate Sub Button1_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim t As New Threading. Thread (Addressof Checkmail) T.Start ()

End Sub

Private Sub Form1_Load (Byval E AS System.Object, Byval E AS System.Eventargs) Handles MyBase.Load

End Subend Class

转载请注明原文地址:https://www.9cbs.com/read-49838.html

New Post(0)