Search The ForumSearch   RegisterRegister  LoginLogin

MailBee.NET POP3

 AfterLogic Forum : MailBee.NET POP3
Subject Topic: Multiple pop connections Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
juris
Groupie
Groupie


Joined: 27 June 2011
Location: Italy
Online Status: Offline
Posts: 67
Posted: 06 June 2012 at 9:29am | IP Logged Quote juris

Hi,

How I Implement this?

****************************************+
foreach (DataRow drAccount in DSManager.MyDataSet.Accounts.Rows)
{
     try
        {
             string Pop3ServerName = drAccount["Pop3ServerName"].ToString();
               string Pop3Port = (int)drAccount["Pop3Port"];


          // Try to connect to the mail server keeping UI of the application
               // alive. The rest of the POP3 conversation will be made in the callback.
               pop.BeginConnect(Pop3ServerName, Pop3Port, true,
               new AsyncCallback(ConnectCallbackAndGetMessageList), null);

     }
        catch
        {
             //ERROR!!!
        }
}
*******************************************

Back to Top View juris's Profile Search for other posts by juris
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 06 June 2012 at 9:44am | IP Logged Quote Alex

You just need to create separate Pop3 instance for each async connection. Each instance will then create its own thread when you call async method, and you'll use callback to control when the method finishes. You can also pass state parameter to async method (which will then pass it to callback), and you can use this parameter to distinguish between different Pop3 instances in your callback.

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 
juris
Groupie
Groupie


Joined: 27 June 2011
Location: Italy
Online Status: Offline
Posts: 67
Posted: 06 June 2012 at 10:30am | IP Logged Quote juris

Alex wrote:
You can also pass state parameter to async method (which will then pass it to callback), and you can use this parameter to distinguish between different Pop3 instances in your callback.


Hi Alex,

You can write an example with this second method?

Regards,
Lello
Back to Top View juris's Profile Search for other posts by juris
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 06 June 2012 at 10:50am | IP Logged Quote Alex

It's standard async pattern of .net applications, nothing specific to MailBee.

For instance, state parameter is used in Imap.BeginCopyOrMoveMessages example. The idea is all the same.

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 
juris
Groupie
Groupie


Joined: 27 June 2011
Location: Italy
Online Status: Offline
Posts: 67
Posted: 06 June 2012 at 11:01am | IP Logged Quote juris

Ok, Thanks!
Back to Top View juris's Profile Search for other posts by juris
 
juris
Groupie
Groupie


Joined: 27 June 2011
Location: Italy
Online Status: Offline
Posts: 67
Posted: 06 June 2012 at 9:17pm | IP Logged Quote juris

Alex wrote:
You just need to create separate Pop3 instance for each async connection. Each instance will then create its own thread when you call async method, and you'll use callback to control when the method finishes.


Hi,

How can I fix this exception?

******************************************
//MailBee Pop3
private Pop3 pop = null;

foreach (DataRow drAccount in MyDataSet.Accounts.Rows)
{
     try
        {
             string Pop3ServerName = drAccount["Pop3ServerName"].ToString();
             int Pop3Port = (int)drAccount["Pop3Port"];

             //New istance
             pop = new pop3();

             pop.BeginConnect(Pop3ServerName, Pop3Port, true,
               new AsyncCallback(ConnectCallbackAndGetMessageList), null);

     }
        catch
        {
             //EXCEPTION!!!
             EndInvoke can only be called once for each asynchronous operation.
        }
}
Back to Top View juris's Profile Search for other posts by juris
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 07 June 2012 at 3:20am | IP Logged Quote Alex

You're not using 'state' parameter as described in the sample I referred (so how will the callback know for which Pop3 instance it should complete the operation?), and Pop3 instances are never stored in array or somewhat like that, you overwrite the same pop instance all the time and only god knows what happens with overwritten instances.

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 
juris
Groupie
Groupie


Joined: 27 June 2011
Location: Italy
Online Status: Offline
Posts: 67
Posted: 07 June 2012 at 5:11am | IP Logged Quote juris

Alex wrote:
You're not using 'state' parameter as described in the sample I referred (so how will the callback know for which Pop3 instance it should complete the operation?), and Pop3 instances are never stored in array or somewhat like that, you overwrite the same pop instance all the time and only god knows what happens with overwritten instances.


Hi,

I added the parameter "state", but the same exception.
EndInvoke can only be called once for each asynchronous operation
How can I fix this exception?

******************************************
        public class PopState
        {
            public Pop3 Pop { get; set; }
            public string AccountName { get; set; }
            public string Pop3ServerName { get; set; }
            public int Pop3Port { get; set; }
            public string Pop3UserName { get; set; }
            public string Pop3Password { get; set; }
            public bool Pop3TrySecureAuth { get; set; }
            public bool Pop3NewerMessagesFirst { get; set; }

            public PopState(Pop3 pop, string accountName, string pop3ServerName, int pop3Port, string pop3UserName, string pop3Password, bool pop3TrySecureAuth, bool pop3NewerMessagesFirst)
            {
               Pop = pop;
               AccountName = accountName;
               Pop3ServerName = pop3ServerName;
               Pop3Port = pop3Port;
               Pop3UserName = pop3UserName;
               Pop3Password = pop3Password;
               Pop3TrySecureAuth = pop3TrySecureAuth;
               Pop3NewerMessagesFirst = pop3NewerMessagesFirst;
            }
        }

******************************************

//MailBee Pop3
private Pop3 pop = null;

foreach (DataRow drAccount in MyDataSet.Accounts.Rows)
{
     try
        {
             string Pop3ServerName = drAccount["Pop3ServerName"].ToString();
             int Pop3Port = (int)drAccount["Pop3Port"];

             //New istance
             pop = new pop3();

             //New Istance
             PopState state = new PopState(pop, drAccount["Nome_Account"].ToString(), drAccount["Pop3ServerName"].ToString(), (int)drAccount["Pop3Port"], drAccount["Pop3UserName"].ToString(), drAccount["Pop3Password"].ToString(), (bool)drAccount["Pop3TrySecureAuth"], (bool)drAccount["Pop3NewerMessagesFirst"]);


             pop.BeginConnect(Pop3ServerName, Pop3Port, true,
               new AsyncCallback(ConnectCallbackAndGetMessageList), state);

     }
        catch
        {
             //EXCEPTION!!!
             EndInvoke can only be called once for each asynchronous operation.
        }
Back to Top View juris's Profile Search for other posts by juris
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 07 June 2012 at 5:21am | IP Logged Quote Alex

Refer to Imap.BeginCopyOrMoveMessages example on how to use state parameter in callbacks.

Passing state parameter itself is useless if you never consume it.

Also, you'll need to learn C# async BeginXXX/EndXXX programming pattern to get the idea how these things work. From your questions, I see that things you're asking are not specific to MailBee, they are more general. You may start with checking the docs in MSDN on System.Net.Socket async methods, like Socket.BeginReceive. Once you get the idea, it should be no problem to use this for MailBee because it uses exactly the same pattern. In this forum, it's only possible to provide assistance on MailBee-specific things.

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 
juris
Groupie
Groupie


Joined: 27 June 2011
Location: Italy
Online Status: Offline
Posts: 67
Posted: 07 June 2012 at 5:50am | IP Logged Quote juris

Hi,

I can not do.
You can write an example?

Regards, Lello :-)
Back to Top View juris's Profile Search for other posts by juris
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 07 June 2012 at 5:54am | IP Logged Quote Alex

Writing custom code for clients is beyond the scope of a free technical support but you can request a quote for consulting services (we have a special department for this). Please contact us via HelpDesk for details.

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 
juris
Groupie
Groupie


Joined: 27 June 2011
Location: Italy
Online Status: Offline
Posts: 67
Posted: 07 June 2012 at 9:55am | IP Logged Quote juris

Alex wrote:
Writing custom code for clients is beyond the scope of a free technical support but you can request a quote for consulting services (we have a special department for this). Please contact us via HelpDesk for details.


Even if you did not help me I managed to do the same
Thank you :-)

Lello

Back to Top View juris's Profile Search for other posts by juris
 
juris
Groupie
Groupie


Joined: 27 June 2011
Location: Italy
Online Status: Offline
Posts: 67
Posted: 07 June 2012 at 10:45am | IP Logged Quote juris

In this way it works...

*********************************************

public class PopObject
{
    public Pop3 Pop { get; set; }
    public string AccountName { get; set; }
    public string Pop3ServerName { get; set; }
    public int Pop3Port { get; set; }
    public string Pop3UserName { get; set; }
    public string Pop3Password { get; set; }
    public bool Pop3TrySecureAuth { get; set; }
    public bool Pop3NewerMessagesFirst { get; set; }
    public bool Pop3DeleteMessagesAftherDownload { get; set; }
    public MailMessageCollection Msgs { get; set; }
}

*********************************************

foreach (DataRow drAccount in MyDataSet.Accounts.Rows)
{
try
{
     //New istance
      pop = new pop3();

      //New Istance
      msgs = new MailMessageCollection();

      PopObject popObject = new PopObject();
      {
           popObject.Pop = pop;
           popObject.AccountName = drAccount["AccountName"].ToString();
           popObject.Pop3ServerName = drAccount["Pop3ServerName"].ToString();
           popObject.Pop3Port = (int)drAccount["Pop3Port"];
           popObject.Pop3UserName = drAccount["Pop3UserName"].ToString();
           popObject.Pop3Password = drAccount["Pop3Password"].ToString();
           popObject.Pop3TrySecureAuth = (bool)drAccount["Pop3TrySecureAuth"];
           popObject.Pop3DeleteMessagesAftherDownload = false;
           popObject.Pop3NewerMessagesFirst = false;
           popObject.Msgs = msgs;
      }

      popObject.Pop.BeginConnect(popObject.Pop3ServerName, popObject.Pop3Port, true,
                                 &n bsp;  new AsyncCallback(ConnectCallbackAndGetMessageList), popObject);

}
catch
{
    //In this way it works !!!
}
}

*********************************************

private void ConnectCallbackAndGetMessageList(IAsyncResult result)
{
     PopObject popObject = (PopObject)result.AsyncState;

     //........

     // The message headers are downloaded, so we may disconnect now.
     popObject.Pop.Disconnect();           
}

*********************************************
Back to Top View juris's Profile Search for other posts by juris
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide