Reading Email from .net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • wondersoft
    New Member
    • Mar 2010
    • 1

    Reading Email from .net

    Class File in C#
    -----------------------
    Code:
     // connect to pop server
         SmtPop.POP3Client pop = new SmtPop.POP3Client ();
           pop.Open ("localhost", "110", "mylogin", "mypasword");
      
         // get messages list from pop server
         SmtPop.POPMessageId[] messages = pop.GetMailList ();
      
         if (messages != null)
          {
               // Walk attachment list
               foreach (SmtPop.POPMessageId id in messages)
               {
                   SmtPop.POPReader reader = pop.GetMailReader (id.Id);
                   SmtPop.MimeMessage msg = new SmtPop.MimeMessage ();
      
                   // read message
                   msg.Read (reader);
                   if (msg.Attachments != null)
                   {
                       // do something with first attachment
                     SmtPop.MimeAttachment attach = msg.Attachments[0];
                       if (attach.Filename == "data")
                       {
                           // read data from attachment
                           Byte[] b = Convert.FromBase64String (attach.Body);
      
                           System.IO.MemoryStream mem = new System.IO.MemoryStream (b, false);
                           BinaryFormatter f = new BinaryFormatter ();
                         DataClass data = (DataClass) f.Deserialize (mem); 
                         mem.Close();
                     }                          
      
                     //delete message
                     pop.Dele (id.Id);
                       }
                   }
               }
         }
      
         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
    Last edited by tlhintoq; Mar 16 '10, 02:25 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    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.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      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.

      Comment

      Working...