Detect new mail in vb.net

Source: Internet
Author: User
Tags integer mail connect readline
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
......

Private Function Connect (ByVal strserver As String, ByVal struser As String, ByVal strpwd as String) as NetworkStream
Dim Sender as New tcpclient (strserver, 110)
Dim outbytes as Byte ()
Dim Input as String
Dim Ns as NetworkStream = Nothing

Try
Ns = Sender.getstream ()
Dim SR as New StreamReader (Ns)
input = "User" & struser & VbCrLf
Outbytes = System.Text.Encoding.ASCII.GetBytes (input)
Ns.write (outbytes, 0, Outbytes.length)
Console.WriteLine (Sr. ReadLine ())
input = "Pass" & Strpwd & VbCrLf
Outbytes = System.Text.Encoding.ASCII.GetBytes (input)
Ns.write (outbytes, 0, Outbytes.length)
Console.WriteLine (Sr. ReadLine ())
Console.WriteLine ("==========================================================")
Return Ns
Catch ex as Exception
MsgBox ("Unable to connect to server", msgboxstyle.critical)
Return Ns
End Try
End Function

Private Function getnumberofnewmessages () as Integer
Dim outbytes as Byte ()
Dim Input as String
Dim strtemp as String

Getnumberofnewmessages =-1
Try
Dim Ns as NetworkStream = Connect ("Enter mail server name here", "username", "password")
If (Ns is Nothing) Then Exit Function
Dim SR as New StreamReader (Ns)
input = "Stat" & VbCrLf
Outbytes = System.Text.Encoding.ASCII.GetBytes (input)
Ns.write (outbytes, 0, Outbytes.length)
Dim resp as String = Sr. ReadLine ()
Console.WriteLine (RESP)
Dim tokens as String () = resp. Split ("")
input = "Quit" & VbCrLf
Outbytes = System.Text.Encoding.ASCII.GetBytes (input)
Ns.write (outbytes, 0, Outbytes.length)
Console.WriteLine (Sr. ReadLine ())
Sr. Close ()
Ns.close ()
Return Val (Tokens (1))
Catch ex as Exception
Console.WriteLine (ex. ToString)
End Try
End Function
Private Sub button1_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button1.Click
Dim intnew As Integer

Intnew=getnumberofnewmessages ()
MsgBox "Have" & CStr (intnew) & "new email!" "
End Sub




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.