Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8022187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:11:47+00:00 2026-06-04T22:11:47+00:00

I’m here to ask you the following: how do I store the Unique ID

  • 0

I’m here to ask you the following: how do I store the Unique ID from a message in a POP server into my database, when using the OpenPop.Net library? Here’s the “FetchMessage” function:

public static List<OpenPop.Mime.Message> FetchUnseenMessages(string hostname, int port, bool useSsl, string username, string password, List<string> seenUids)
    {
        // The client disconnects from the server when being disposed
        using (Pop3Client client = new Pop3Client())
        {
            // Connect to the server
            client.Connect(hostname, port, useSsl);

            // Authenticate ourselves towards the server
            client.Authenticate(username, password, AuthenticationMethod.UsernameAndPassword);

            // Fetch all the current uids seen
            List<string> uids = client.GetMessageUids();



            // Create a list we can return with all new messages
            List<OpenPop.Mime.Message> newMessages = new List<OpenPop.Mime.Message>();

            // All the new messages not seen by the POP3 client
            for (int i = 0; i < uids.Count; i++)
            {
                string currentUidOnServer = uids[i];
                if (!seenUids.Contains(currentUidOnServer))
                {
                    // We have not seen this message before.
                    // Download it and add this new uid to seen uids

                    // the uids list is in messageNumber order - meaning that the first
                    // uid in the list has messageNumber of 1, and the second has 
                    // messageNumber 2. Therefore we can fetch the message using
                    // i + 1 since messageNumber should be in range [1, messageCount]
                    OpenPop.Mime.Message unseenMessage = client.GetMessage(i + 1);

                    // Add the message to the new messages
                    newMessages.Add(unseenMessage);

                    // Add the uid to the seen uids, as it has now been seen
                    seenUids.Add(currentUidOnServer);
                }
            }

            // Return our new found messages
            return newMessages;
        }
    }

And here’s part of the “GetEMail” function (the one that calls the above one)(Also the comments are in Portuguese…):

//primeiro obter informação de contas
        SqlCeConnection Con = conecao.ligardb(); //ligar a base de dados
        Con.Open();
        string myQuery = "SELECT * FROM Contas"; //construir query
        SqlCeCommand myCommand = new SqlCeCommand(myQuery, Con); //construir comando
        SqlCeDataReader myDataReader = myCommand.ExecuteReader(); //executar comando e armazenar informações

        while (myDataReader.Read()) //ler data reader repetidamente
        {
            int tipo = Convert.ToInt32(myDataReader["Tipo"]); //obter tipo de conta
            bool seguro = Convert.ToBoolean(myDataReader["Seguro"]); //obter se e seguro ou nao
            int idConta = Convert.ToInt32(myDataReader["ID"]); //obter id de conta

            if (tipo == 1 && seguro == false) //POP3 sem SSL
            {
                string hostname = Convert.ToString(myDataReader["Serv_Recep"]); //obter servidor de recepçao
                string user = Convert.ToString(myDataReader["User"]); //obter id de utilizador
                string pass = Convert.ToString(myDataReader["Pass"]); //obter pass de utilizador

                List<string> Uids = new List<string>(); //lista para obter e-mails ja obtidos

                //Obter pasta
                string query_pasta = "SELECT id FROM Pastas WHERE idContas=@id AND Nome=@nome";
                SqlCeCommand cmd_pasta = new SqlCeCommand(query_pasta, Con);
                cmd_pasta.Parameters.AddWithValue("@id", idConta);
                cmd_pasta.Parameters.AddWithValue("@nome", "Recebidas");


                SqlCeDataReader dr_pasta = cmd_pasta.ExecuteReader();
                dr_pasta.Read();
                int idPasta = Convert.ToInt32(dr_pasta["id"]);

                //obrer e-mails ja obtidos
                string query = "SELECT Uids FROM Mensagens WHERE Conta=@id AND Pasta=@pasta"; //contruir query
                SqlCeCommand command = new SqlCeCommand(query, Con); //construir comando
                //atribuir parametros
                command.Parameters.AddWithValue("@id", idConta);
                command.Parameters.AddWithValue("@pasta", idPasta);

                SqlCeDataReader datareader = command.ExecuteReader(); //executar e ler comando

                while (datareader.Read()) //ler datareader
                {
                    string ids = Convert.ToString(datareader["Uids"]); //obter uid
                    Uids.Add(ids); //adicionar uid

                }

                List<OpenPop.Mime.Message> NewMessage = new List<OpenPop.Mime.Message>(); //criar lista de mensagens
                NewMessage = FetchUnseenMessages(hostname, 110, false, user, pass, Uids); //obter mensagens

                for (int y = 0; y < NewMessage.Count; y++)
                {
                    //Guardar mensagem em disco
                    string file_name = NewMessage[y].Headers.MessageId;
                    file_name = file_name + ".eml";



                    string path = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\izzy_mail\\" + Convert.ToString(myDataReader["Endereço"]) + "\\Recebidos\\"; //Criar directorioa de destino do .eml
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);

                    }

                    path = path + file_name;

                    FileStream File = System.IO.File.Create(path);

                    NewMessage[y].Save(File);




                    //Guardar na base de dados
                    string assunto = NewMessage[y].Headers.Subject;//obter assunto
                    string origem = NewMessage[y].Headers.From.Address; //obter origem
                    string uid = NewMessage[y].Headers.MessageId; //obter id da mensagem
                    //criar nova query
                    string query_ins = "INSERT INTO Mensagens (Assunto, De, Pasta, Uri, Uids, Conta) VALUES (@assunto, @de, @pasta, @uri, @uid, @id)"; //contruir query
                    SqlCeCommand cmd_ins = new SqlCeCommand(query_ins, Con); //construir comando
                    //parametrizar o comando
                    cmd_ins.Parameters.AddWithValue("@assunto", assunto);
                    cmd_ins.Parameters.AddWithValue("@de", origem);
                    cmd_ins.Parameters.AddWithValue("@id", idConta);
                    cmd_ins.Parameters.AddWithValue("@pasta", idPasta);
                    cmd_ins.Parameters.AddWithValue("@uid", uid);
                    cmd_ins.Parameters.AddWithValue("@uri", path);


                    cmd_ins.ExecuteNonQuery(); //Executar insert



                }


            }
            else if

So anyone has an idea of how to solve my problem?

Thanks in advance…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:11:48+00:00Added an answer on June 4, 2026 at 10:11 pm

    So, with the help of Ben I’ve come to this solution:

    1. I’ve created a public list named UID
    2. Added the following code after newMessage.Add() in the FetchUnseenMessages() function:

      Uid.Add(currentUidOnServer);

    3. Replaced

      string uid = NewMessage[y].Headers.MessageId; //obter id da mensagem

    With:

    string uid = Uid[y]; //obter id da mensagem
    

    And now it works!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I have a view passing on information from a database: def serve_article(request, id): served_article
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.