Click here to Skip to main content
15,917,953 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: How to use Admin account for windows application? Pin
Mark Churchill19-Aug-07 15:23
Mark Churchill19-Aug-07 15:23 
QuestionRe: How to use Admin account for windows application? Pin
Jwalant Natvarlal Soneji19-Aug-07 20:22
Jwalant Natvarlal Soneji19-Aug-07 20:22 
QuestionHow to get unread mail from server Pin
rahul.net1118-Aug-07 0:12
rahul.net1118-Aug-07 0:12 
AnswerRe: How to get unread mail from server Pin
green2go18-Aug-07 1:46
green2go18-Aug-07 1:46 
GeneralRe: How to get unread mail from server Pin
rahul.net1118-Aug-07 2:45
rahul.net1118-Aug-07 2:45 
GeneralRe: How to get unread mail from server Pin
green2go18-Aug-07 3:47
green2go18-Aug-07 3:47 
GeneralRe: How to get unread mail from server Pin
rahul.net1118-Aug-07 3:58
rahul.net1118-Aug-07 3:58 
GeneralRe: How to get unread mail from server [modified] Pin
green2go18-Aug-07 12:11
green2go18-Aug-07 12:11 
Hi Rahul,

I have made an example by modifing the code you posted to log message numbers to a text file. I took out some of your code so you will need to re-intergate it. This code is not perfect (i.e. you will need to add some additional error handling and a few other bits). The server I tested this with is a CPOP UNIX server, so you may need to adapt it to read the server responses differently for other POP3 servers.

UPDATE: If you need it I have a working VB project.

Let me know how you get on.

Regards

Green2Go

Public Function UserInfo(ByVal uname As String, ByVal emailid As String, ByVal pwd As String, ByVal servername As String) As String

'Setup message logging text file
Try
'See whether the file already exists
If File.Exists(Path) Then
'If it does, load contents info var
MsgIDs = My.Computer.FileSystem.ReadAllText(Path)
'Make sure MsgIDs var is not nothing (for compare method below)
If MsgIDs = Nothing Then
MsgIDs = ""
End If
Else
'If it doesn't, prompt to create a new one
Dim result As MsgBoxResult = MsgBox("No message logging file. Create one?", MsgBoxStyle.YesNo)
'If user clicks yes
If result = MsgBoxResult.Yes Then
'Create new text file
Dim fs As FileStream = File.Create(Path)
fs.Close()
Else
'If user clicks no, exit application
MsgBox("The application must exit!", MsgBoxStyle.Critical, "Application Error!")
Application.Exit()
Exit Try
End If
End If
'Catch any exceptions
Catch Ex As Exception
'Show dialogue box with exception info
MsgBox("Could not find / open / create the message log file! The following error was encountered:" + vbCrLf(1) + ex.Message, MsgBoxStyle.Critical, "Application Error!")
Application.Exit()
End Try

Try
'Create new TCP/IP connection
Server = New TcpClient(servername, 110)

'Declare stream
NetStrm = Server.GetStream

'Declare stream reader
RdStrm = New StreamReader(NetStrm)

'Send Username
Data = "USER " + emailid + vbCrLf(1)
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray())
NetStrm.Write(szData, 0, szData.Length)

'Send Password
Data = "PASS " + pwd + vbCrLf(1)
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray())
NetStrm.Write(szData, 0, szData.Length)

'Send List Command
Data = "LIST" + vbCrLf(1)
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray())
NetStrm.Write(szData, 0, szData.Length)


'Read some rogue lines from mail server, you need to move these up and implement some error catching Smile | :)
RdStrm.ReadLine() 'Server replying +OK to connection
RdStrm.ReadLine() 'Server accepting username and asking for password
RdStrm.ReadLine() 'Server accepting password and giving some account information
RdStrm.ReadLine() 'First line of response to the LIST command


'Read first line of the message list into var
Dim line As String = RdStrm.ReadLine()

'Setup message count limiting var
Dim SvrMsgQueueLen As Integer = 0

'Cycle through the rest of the LIST output from the server which is terminated with a period (.) upto
'our limit of messages which is set by the array length of SvrMsgQueue
While line <> "." And SvrMsgQueueLen < SvrMsgQueue.Length
'Add each line into an array
SvrMsgQueue(Array.IndexOf(SvrMsgQueue, Nothing)) = line
'Read next line
line = RdStrm.ReadLine()
'Increment Limit Counter
SvrMsgQueueLen += 1
End While

'If the limit has been reached the display message to user
If SvrMsgQueueLen = SvrMsgQueue.Length Then
MsgBox(SvrMsgQueueLen.ToString + " messages have been processed, which is the maximum limit for this application. Please clear old mail from your mailbox and try again.")
End If

'Declare var to count messages that have already been downloaded
Dim MsgsDownloaded As Integer = 0
'Cycle throut each message we put into the SvrMsgQueue array
For Each msg In SvrMsgQueue
'If the array key does not equal nothing carry on
If msg <> Nothing Then
'If the message ID and Size of the message are already in the message log file do this
If InStr(MsgIDs, msg, CompareMethod.Text) Then
'Message Already Downloaded - Increment counter
MsgsDownloaded += 1
Else
'Messsage Not Downloaded
'Do what you want with the message here
'Split the message ID and message size
Dim thisMessage = msg.ToString.Split(" ")
'Show dialogue box with information
MsgBox("This message has and id of " + thisMessage(0) + " and its size is " + thisMessage(1) + "k")
'Add message ID to list of downloaded
MsgIDs = MsgIDs + vbCrLf + msg
End If
End If
Next
'Message box showing how many we've skipped
MsgBox("There were " + MsgsDownloaded.ToString + " messages that have already been downloaded.")

' Save list of message IDs
File.WriteAllText(Path, MsgIDs)


'Start Clearing Up

' Write to stream and logoff server
Data = "QUIT" + vbCrLf(1)
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray())
NetStrm.Write(szData, 0, szData.Length)

'Close our TCP/IP connection
Server.Close()
Server = Nothing

'Clean some vars up
Server = Nothing
NetStrm = Nothing
RdStrm = Nothing
Data = Nothing
szData = Nothing
MsgIDs = Nothing
msg = Nothing
ReDim SvrMsgQueue(199)


Catch ex As Exception
MsgBox("The following error was encountered:" + ex.Message)
End Try

Return Nothing
End Function



-- modified at 18:53 Saturday 18th August, 2007
AnswerRe: How to get unread mail from server Pin
Dave Kreskowiak18-Aug-07 3:02
mveDave Kreskowiak18-Aug-07 3:02 
GeneralRe: How to get unread mail from server Pin
rahul.net1118-Aug-07 4:02
rahul.net1118-Aug-07 4:02 
QuestionDatagrid row delete Pin
SamRST17-Aug-07 23:38
SamRST17-Aug-07 23:38 
AnswerRe: Datagrid row delete Pin
Jwalant Natvarlal Soneji18-Aug-07 0:41
Jwalant Natvarlal Soneji18-Aug-07 0:41 
GeneralRe: Datagrid row delete Pin
SamRST18-Aug-07 3:58
SamRST18-Aug-07 3:58 
GeneralRe: Datagrid row delete Pin
Jwalant Natvarlal Soneji18-Aug-07 6:30
Jwalant Natvarlal Soneji18-Aug-07 6:30 
Questionxp themes buttons cutting off text? Pin
raventatatatata17-Aug-07 21:57
raventatatatata17-Aug-07 21:57 
AnswerRe: xp themes buttons cutting off text? Pin
Dave Kreskowiak18-Aug-07 3:00
mveDave Kreskowiak18-Aug-07 3:00 
GeneralRe: xp themes buttons cutting off text? Pin
raventatatatata18-Aug-07 5:02
raventatatatata18-Aug-07 5:02 
GeneralRe: xp themes buttons cutting off text? Pin
Dave Kreskowiak18-Aug-07 9:33
mveDave Kreskowiak18-Aug-07 9:33 
GeneralRe: xp themes buttons cutting off text? Pin
raventatatatata18-Aug-07 19:33
raventatatatata18-Aug-07 19:33 
GeneralRe: xp themes buttons cutting off text? Pin
Dave Kreskowiak19-Aug-07 3:30
mveDave Kreskowiak19-Aug-07 3:30 
GeneralRe: xp themes buttons cutting off text? Pin
raventatatatata19-Aug-07 19:55
raventatatatata19-Aug-07 19:55 
GeneralRe: xp themes buttons cutting off text? Pin
Dave Kreskowiak20-Aug-07 1:58
mveDave Kreskowiak20-Aug-07 1:58 
GeneralRe: xp themes buttons cutting off text? Pin
raventatatatata22-Aug-07 15:31
raventatatatata22-Aug-07 15:31 
GeneralRe: xp themes buttons cutting off text? Pin
Dave Kreskowiak22-Aug-07 16:22
mveDave Kreskowiak22-Aug-07 16:22 
GeneralRe: xp themes buttons cutting off text? Pin
raventatatatata23-Aug-07 16:43
raventatatatata23-Aug-07 16:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.