|
What account does it use, with windows application built on vb.net on framework 1.1, when we fetch an image in to picturebox?
Jwalant Soneji (BE IT)
Mobile: +91 9969059127
http://jnsoneji.spaces.live.com
http://jnsoneji.blogspot.com
|
|
|
|
|
Hi
I am developing an application in which i am downloading mails from
server into a text box.I am able to download mails from server.But
now i want to download only those mail which are new (i.e unread)
how can i know which mails are unread so that i can download it.
Please guide me to solve this problem.
Thanks.
-- modified at 7:34 Saturday 18th August, 2007
Rahul
|
|
|
|
|
Most POP3 mail clients (assuming POP3 is the protocol your using?) keep a log of the items that have been downloaded (read) from the server locally, to my knowledge there is no per article read information kept by the server. See this RFC article for the ins and outs of the POP3 protocol.
RFC 1939 - Post Office Protocol - Version 3
Green2Go
|
|
|
|
|
Hi
Can u tell me how can i keep log of the items that have been
read.Can you give some hint to me regarding to that.
like some sample code for that.
Thanks.
Rahul
|
|
|
|
|
Rahul,
Please answer the following questions to allow me to help you further:
1. Which protocol are you using to connect to the server? (POP3 / IMAP / Exchange / etc)
2. How are you connecting from your .NET code to the server? Are you using a plugin like Jscapes E-Mail Factory or have you developed your own code to connect to the server?
I cannot provide you with sample code or give direction on how to log message IDs to file unless you give me more info to work with.
To give you a pointer if you are using POP3, all messages on the server have a unique message ID which you will need to use to retrieve or delete a message from the server. I suggest you keep a local list of the message IDs that your app has downloaded. You can then reference that file to see whether the ID is in the list, therefore determining whether the e-mail has been downloaded (read). A simple way of keeping the IDs to start with would be in a text file.
Green2Go
|
|
|
|
|
Hi green2go
i am using POP3 protocol to connect to server.
i have developed my own code to connect to server.
the code i have used is as follow.
Public Function UserInfo(ByVal uname As String, ByVal emailid As String, ByVal pwd As String, ByVal servername As String) As String<br />
CRLF = "\r\n"<br />
Dim cr As Cursor = Windows.Forms.Cursor.Current<br />
Windows.Forms.Cursor.Current = Cursors.WaitCursor<br />
Server = New TcpClient(servername, 110)<br />
Try<br />
NetStrm = Server.GetStream<br />
RdStrm = New StreamReader(Server.GetStream())<br />
'Status.Items.Add(RdStrm.ReadLine())<br />
msg = RdStrm.ReadLine()<br />
<br />
Data = "USER " + emailid + CRLF<br />
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray())<br />
NetStrm.Write(szData, 0, szData.Length)<br />
'Status.Items.Add(RdStrm.ReadLine())<br />
<br />
Data = "PASS " + pwd + CRLF<br />
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray())<br />
NetStrm.Write(szData, 0, szData.Length)<br />
' Status.Items.Add(RdStrm.ReadLine())<br />
<br />
Data = "STAT" + CRLF<br />
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray())<br />
NetStrm.Write(szData, 0, szData.Length)<br />
' Status.Items.Add(RdStrm.ReadLine())<br />
Dim st As String = RdStrm.ReadLine<br />
Cursor.Current = cr<br />
<br />
'''''''''''''Retriving mails'''''''''''<br />
'Recievemail()<br />
<br />
Dim szTemp As String<br />
'Dim str1 As String = String.Empty<br />
<br />
Dim i As String = "54"<br />
Dim abc As New TextBox<br />
'Dim cr As Cursor = Windows.Forms.Cursor.Current<br />
cr = Windows.Forms.Cursor.Current<br />
Windows.Forms.Cursor.Current = Cursors.WaitCursor<br />
Try<br />
Data = "RETR " + i + CRLF<br />
szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray())<br />
NetStrm.Write(szData, 0, szData.Length)<br />
<br />
szTemp = RdStrm.ReadLine()<br />
<br />
If (szTemp(0) <> "-") Then<br />
While szTemp <> "."<br />
str += szTemp + CRLF<br />
'abc.Text += szTemp + CRLF<br />
szTemp = RdStrm.ReadLine()<br />
<br />
End While<br />
Else<br />
'Status.Items.Add(szTemp)<br />
Cursor.Current = cr<br />
<br />
End If<br />
Catch err As Exception<br />
'Status.Items.Add("Error: " + err.ToString())<br />
Console.Write(err.Message)<br />
End Try<br />
<br />
'''''code end here''''<br />
Catch err As InvalidOperationException<br />
Console.Write(err.Message)<br />
End Try<br />
Return str<br />
<br />
End Function<br />
I am passing this four values to function on page load( i.e. my email servername and password.)Now currently i am retrieving email no 53( i put email no as hard coded because i dont know how to retrieve unread mail.)
Thanks.
Rahul
|
|
|
|
|
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
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
|
|
|
|
|
Don't repost the same question multiple times in the same day. You didn't give anyone any kind of chance to answer your question the first time, then you reposted it 4 hours later. It's considered rude to spam the forums.
|
|
|
|
|
No i didn't post the same question again and again.
Please read the first question carefully and then told abt that.
In first question i am asking how to retrieve mails from server
and now am able to retrieve mail but i am having problem how
to get unread mails.
Thanks.
Rahul
|
|
|
|
|
hi frnds..
i want to delete a row in datagrid when i select a row and press delete button,,, is there any event for that or how can i do this..
plse help me quick..
cheers..
|
|
|
|
|
Dear SamRST,
If you have added a delete column then can get the e on datagrid itemcommand event and the e.item.itemindex will give you the index and you can get the value of that row by this index and can delete that, or use select column and get the selected index changed event of that grid to do so.
Jwalant Soneji (BE IT)
Mobile: +91 9969059127
http://jnsoneji.spaces.live.com
http://jnsoneji.blogspot.com
|
|
|
|
|
thnks for reply,
its not enough bcose, i'm using windows forms , not web forms.. for web forms, its okay... but ..
cheers
|
|
|
|
|
ohh sorry, did not realize that...
Jwalant Soneji (BE IT)
Mobile: +91 9969059127
http://jnsoneji.spaces.live.com
http://jnsoneji.blogspot.com
|
|
|
|
|
I have just used the System.Windows.Forms.Application.EnableVisualStyles() method to enable the visual styles on an application but when I do it cuts the text off like there's too much padding around the text on the buttons.
Any help?
|
|
|
|
|
You're choices are obvious, but limited. Either make the buttons a bit bigger, or make the font you're using for the button text a bit smaller.
|
|
|
|
|
Well, it's not something that seems at all normal. Take a look...
PIC!
It's just wierd...
|
|
|
|
|
Since the text that is showing is missing the right side characters, but is still perfectly centered, it looks like the string being sent to the button is actually what's being displayed. In other words, it appears that the contents of the Text property is actually "Canc", not "Cancel".
|
|
|
|
|
That would appear to be the case but i would really like to know why it would only be passing that much to the form and why it hasn't happend to one of the other buttons...
This happens whether i use a dot manifest file or whether i use the activate visual styles method.
Has anyone else run into this problem, or could it just be my version of visual studio?
Cheers
Russ
|
|
|
|
|
Are you using .NET 1.1 (VS.NET 2003)???
If so, put this immediately after the EnableVisualStyles line:
Application.DoEvents()
<div class="ForumSig"><small><a href="http://www.codeproject.com/scrapbook/ForumGuidelines.asp">A guide to posting questions on CodeProject</a>[<a href="http://www.codeproject.com/scrapbook/ForumGuidelines.asp" target="_blank" title="New Window">^</a>]</small><br>
<font color="Blue">Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic<br> 2006, 2007</font>
</div>
|
|
|
|
|
Thanks, OK:
I tried adding the Apllication.DoEvents() line after it but there's no change.
Is this where I'm supposed to be putting these lines?
Public Sub New()
MyBase.New()
Application.EnableVisualStyles()
Application.DoEvents()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
Thanks again,
Russell
|
|
|
|
|
Are you using .NET 1.1 (VB.NET 2003)?? If not, which version?
|
|
|
|
|
Yes, it's .NET V1.1... is that going to make a difference?
|
|
|
|
|
Yep. There was a bug in the .NET 1.1 version. Where you put the EnableVisualStyles won't work. It's got to be launched before you instantiate your startup form, in a Sub Main. Something like this:
Public Shared Sub Main()
Application.EnableVisualStyles()
Application.DoEvents()
Application.Run(New MyStartupForm)
End Sub
Don't forget to change your project's Startup Form to Sub Main, instead of the actual form.
|
|
|
|
|
Thanks. I will give this a try tonight...
Cheers,
Russ
|
|
|
|
|
There must be something really wrong with my version coz even if I do that it still cuts stuff off!?
I'm downloading the express edition of 2005 as I type so I reckon that'll set me straight here. (HOPE SO ANYHOW!)
Cheers for the help,
Russ
|
|
|
|