locked
How to pull mail from mail server and save to db by C# RRS feed

  • Question

  • User264732274 posted

    we have mail server in ORCSWeb and we want to design a application which will pull mail from our mail server and save to database. tell me how to pull mail from our mail server and save to database ?

    table in db will have fields like From, To, CC, Bcc, Subject and body, send time. after pulling it we want to extract info from mail for From, To, CC, Bcc, Subject and body and sendtime and save to db. when again some one reply that mail then we have save that replied mail in db but i need to create relation between mail and their reply. guide me how to achieve it. thanks

    Thursday, October 15, 2015 2:11 PM

Answers

  • User859425685 posted

    You can use a library link OpenPOP.Net to retrieve POP Emails.

    http://sourceforge.net/projects/hpop/

    http://hpop.sourceforge.net/

    Here is an example to get email from gmail.

            // The client disconnects from the server when being disposed
        using(Pop3Client client = new Pop3Client())
        {
            // Connect to the server
            client.Connect("imap.gmail.com", 995, true);

            // Authenticate ourselves towards the server
            client.Authenticate("youremail@gmail.com", "yourpassword");

            // Get the number of messages in the inbox
            int messageCount = client.GetMessageCount();

            // We want to download all messages
            List<Message> allMessages = new List<Message>(messageCount);

            // Messages are numbered in the interval: [1, messageCount]
            // Ergo: message numbers are 1-based.
            // Most servers give the latest message the highest number
            for (int i = messageCount; i > 0; i--)
            {
                allMessages.Add(client.GetMessage(i));
            }

            // Now return the fetched messages
            //return allMessages;
        }

    Regards

    Tajinder Sarao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 15, 2015 4:52 PM
  • User-2007877324 posted

    Here is similar post on this

    Reading Email from Exchange Server and Save It on SQL Database

    Also take a look at this approach that uses outlook

    Outlook Email Extractor

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 16, 2015 12:31 AM
  • User859425685 posted

    Hi Sudip

    OpenPOP Message has properties like MessageID and In-Reply-To which can help you. Each message has a MessageID and if the message is in reply to another email it will have InReplyTo property populated. Please go through the documentation at http://hpop.sourceforge.net/documentation/index.html

    http://hpop.sourceforge.net/documentation/OpenPop~OpenPop.Mime.Header.MessageHeader~Members.html

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 16, 2015 3:55 PM

All replies

  • User859425685 posted

    You can use a library link OpenPOP.Net to retrieve POP Emails.

    http://sourceforge.net/projects/hpop/

    http://hpop.sourceforge.net/

    Here is an example to get email from gmail.

            // The client disconnects from the server when being disposed
        using(Pop3Client client = new Pop3Client())
        {
            // Connect to the server
            client.Connect("imap.gmail.com", 995, true);

            // Authenticate ourselves towards the server
            client.Authenticate("youremail@gmail.com", "yourpassword");

            // Get the number of messages in the inbox
            int messageCount = client.GetMessageCount();

            // We want to download all messages
            List<Message> allMessages = new List<Message>(messageCount);

            // Messages are numbered in the interval: [1, messageCount]
            // Ergo: message numbers are 1-based.
            // Most servers give the latest message the highest number
            for (int i = messageCount; i > 0; i--)
            {
                allMessages.Add(client.GetMessage(i));
            }

            // Now return the fetched messages
            //return allMessages;
        }

    Regards

    Tajinder Sarao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, October 15, 2015 4:52 PM
  • User-2007877324 posted

    Here is similar post on this

    Reading Email from Exchange Server and Save It on SQL Database

    Also take a look at this approach that uses outlook

    Outlook Email Extractor

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 16, 2015 12:31 AM
  • User264732274 posted

    @pprasannak my main concern is how to store mail id with relation.

    suppose user1 one send mail to this address vsdev@asp.net and my c# apps will download the mail and save it to db.

    when vsdev give answer to user1@asp.net then how to download that mail and save in db with relation. so when we will display all mail for vsdev@asp.net then we can show and arrange mail with order as a result user can understand what was the first and what was 2nd mail with answer and so on.

    would you be able to guide me. thanks

    Friday, October 16, 2015 8:54 AM
  • User264732274 posted

    i just need more help. so i post a another question to @pprasannak. please see and help me if you know the answer @tssarao.

    thanks

    Friday, October 16, 2015 8:55 AM
  • User859425685 posted

    Hi Sudip

    OpenPOP Message has properties like MessageID and In-Reply-To which can help you. Each message has a MessageID and if the message is in reply to another email it will have InReplyTo property populated. Please go through the documentation at http://hpop.sourceforge.net/documentation/index.html

    http://hpop.sourceforge.net/documentation/OpenPop~OpenPop.Mime.Header.MessageHeader~Members.html

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, October 16, 2015 3:55 PM