473,320 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Reading Email from .net

Class File in C#
-----------------------
Expand|Select|Wrap|Line Numbers
  1.  // connect to pop server
  2.      SmtPop.POP3Client pop = new SmtPop.POP3Client ();
  3.        pop.Open ("localhost", "110", "mylogin", "mypasword");
  4.  
  5.      // get messages list from pop server
  6.      SmtPop.POPMessageId[] messages = pop.GetMailList ();
  7.  
  8.      if (messages != null)
  9.       {
  10.            // Walk attachment list
  11.            foreach (SmtPop.POPMessageId id in messages)
  12.            {
  13.                SmtPop.POPReader reader = pop.GetMailReader (id.Id);
  14.                SmtPop.MimeMessage msg = new SmtPop.MimeMessage ();
  15.  
  16.                // read message
  17.                msg.Read (reader);
  18.                if (msg.Attachments != null)
  19.                {
  20.                    // do something with first attachment
  21.                  SmtPop.MimeAttachment attach = msg.Attachments[0];
  22.                    if (attach.Filename == "data")
  23.                    {
  24.                        // read data from attachment
  25.                        Byte[] b = Convert.FromBase64String (attach.Body);
  26.  
  27.                        System.IO.MemoryStream mem = new System.IO.MemoryStream (b, false);
  28.                        BinaryFormatter f = new BinaryFormatter ();
  29.                      DataClass data = (DataClass) f.Deserialize (mem); 
  30.                      mem.Close();
  31.                  }                          
  32.  
  33.                  //delete message
  34.                  pop.Dele (id.Id);
  35.                    }
  36.                }
  37.            }
  38.      }
  39.  
  40.      pop.Quit ();

But I have a problem i can read the mail only once ... for the next time the it is not avilable
any one can help me out.....
thanks in advance
Mar 16 '10 #1
2 1905
tlhintoq
3,525 Expert 2GB
TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
Mar 16 '10 #2
tlhintoq
3,525 Expert 2GB
But I have a problem i can read the mail only once ... for the next time the it is not avilable
any one can help me out.....
I doubt it's a coding problem. The mail server is probably NOT set to keep a copy of the messages. Once you download the email, it is deleted from the server. Sounds like proper operation to me.
Mar 16 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # to open a file and write to file # do f=open('xfile.txt','w') # this creates a file "object" and name it f. # the second argument of open can be
4
by: Oliver Knoll | last post by:
According to my ANSI book, tmpfile() creates a file with wb+ mode (that is just writing, right?). How would one reopen it for reading? I got the following (which works): FILE *tmpFile =...
4
by: Magix | last post by:
Hi, I would like to check if the data file is empty or not before reading it. How should I achieve that ? fseek/ftell ? ....fopen process here(..) if filesize is 0 // mean empty data printf...
6
by: KevinD | last post by:
assumption: I am new to C and old to COBOL I have been reading a lot (self teaching) but something is not sinking in with respect to reading a simple file - one record at a time. Using C, I am...
4
by: Greg Smith | last post by:
I have an old application that analyzes the data in the event log on one of our servers. I would like to convert it to C#. Does anybody know of any examples of reading the event log on a remote...
2
by: Sabin Finateanu | last post by:
Hi I'm having problem reading a file from my program and I think it's from a procedure I'm using but I don't see where I'm going wrong. Here is the code: public bool AllowUsage() { ...
21
by: JoKur | last post by:
Hello, First let me tell you that I'm very new to C# and learning as I go. I'm trying to write a client application to communicate with a server (that I didn't write). Each message from the...
1
by: Need Helps | last post by:
Hello. I'm writing an application that writes to a file a month, day, year, number of comments, then some strings for the comments. So the format for each record would look like:...
2
by: Jean-Marie Vaneskahian | last post by:
Reading - Parsing Records From An LDAP LDIF File In .Net? I am in need of a .Net class that will allow for the parsing of a LDAP LDIF file. An LDIF file is the standard format for representing...
2
by: Derik | last post by:
I've got a XML file I read using a file_get_contents and turn into a simpleXML node every time index.php loads. I suspect this is causing a noticeable lag in my page-execution time. (Or the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.