ANPOP Developers Center > Programming with Pop3 Queuing

No More ASP Timeout in Retrieving Emails

In ASP/ASP.NET email application, if email download takes longer than the value (in seconds) that the current asp page is allowed to run, user will get an error "ASP Timeout". This often happens  when user has a large quantity of emails to download or user downloads emails over a slow connection. By default the timeout is set to 90 seconds, it is easy to exceed this limit.

Obviously, a solution to ASP timeout is to set ASPScriptTimeout a larger value. You may click here for details. Technically the timeout problem can be solved in this way, however, some users may get frustrated and press the stop button on the browser toolbar as he waits too long.

ANPOP POP3 Component introduces a more intelligent method to retrieve emails in background.

You should download the anpop installer and install it on your machine at first. If you want to distribute or deploy anpop without anpop installer, please click here to learn more.

How does it work?

Firstly, an ASP/ASP.NET application collects pop3 account information and builds a new Pop3Request object based on specified pop3 account. Secondly, it sends this Pop3Request object to local/remote application which runs in background. Finally, the application return to the user and the server application performs task in background.

Code Examples

[ASP/VBScript]

[client application]
This subroutine demonstrates how to send a request to background application.
Sub SendRequest
  Dim oPop3Request, oPop3Queue
  Dim pop3Server, user, password, appAddr, port 
  
  appAddr = "127.0.0.1"
  port = 5157

  pop3Server = "mail.adminsystem.net"
  user = "test@adminsystem.net"
  password = "test"

  Set oPop3Request = Server.CreateObject("ANPOP.Pop3Request")
  Set oPop3Queue = Server.CreateObject("ANPOP.Pop3Queue" )

  oPop3Request.Pop3Server = pop3Server
  oPop3Request.UserName = user
  oPop3Request.Password = password
  oPop3Request.LFlag = 1 'any numeric value which associated with this request
  oPop3Request.SFlag = "any" 'any string value which associated with this request

  If oPop3Queue.SendRequest( appAddr, port, oPop3Request ) = 0 Then
    Response.Write "send request succeeded"
  Else
    Response.Write "send request failed, "
  End 
End Sub

[background application]
This subroutine demonstrates how to receive a request from ASP/ASP.NET.
Sub Receive
  Dim oPop3Queue As ANPOPLib.Pop3Queue
  Dim oPop3Reqest As ANPOPLib.Pop3Request
  Dim MaxConnections, Port As Integer
  
  MaxConnections = 5
  Port = 5157
  Set oPop3Queue = new ANPOPLib.Pop3Queue
  If oPop3Queue.Listen( Port, MaxConnections ) <> 0 Then
	MsgBox "bind port failed"
	Exit Sub
  End If
  
  Do While True
	Set oPop3Request = oPop3Queue.Receive(1)
	If Not (oPop3Request Is Nothing) Then
      'now a request received, then use another subroutine to retrieve email 
      Call RetrieveEmail( oPop3Request.Pop3Server, _
		                oPop3Request.UserName, _ 
		                oPop3Request.Password )
	End If
	Nothing received
	DoEvents
  Loop
End Sub

[ASP.NET/C#]

[client application]
This subroutine demonstrates how to send a request to background application.
public void SendRequest()
{
  string pop3Server = "mail.adminsystem.net";
  string user = "test@adminsystem.net";
  string password = "test";
  string appAddr = "127.0.0.1";
  int port = 5157;
  
  pop3RequestClass oPop3Request =
                      (pop3RequestClass)Server.CreateObject("ANPOP.Pop3Request");
  Pop3QueueClass oPop3Queue = 
                      (Pop3QueueClass)Server.CreateObject("ANPOP.Pop3Queue");
  
  oPop3Request.Pop3Server = pop3Server;
  oPop3Request.UserName = user;
  oPop3Request.Password = password;
  oPop3Request.LFlag = 1; //any numeric value associated with this request
  oPop3Request.SFlag = "any"; //any string value associated with this request
 
  if( oPop3Queue.SendRequest( appAddr, port, oPop3Request ) == 0 )
    Response.Write( "send request succeeded");
  else
    Response.Write( "send request failed, " );
 
 }
 
[background application]
This subroutine demonstrates how to receive a request from ASP/ASP.NET.
public void Receive()
{
  pop3RequestClass oPop3Request = null;
  Pop3QueueClass oPop3Queue = new Pop3QueueClass();
  int MaxConnections = 5, Port = 5157;
  
  if( oPop3Queue.Listen( Port, MaxConnections ) != 0 )
    throw new Exception( "bind 5157 port failed" );
  
  while( true )
  {
    oPop3Request = oPop3Queue.Receive(1);
    if( oPop3Request != null )
    {
      //now a request received, then use another subroutine to retrieve email 
      RetrieveEmail( oPop3Request.Pop3Server,
		                oPop3Request.UserName, 
		                oPop3Request.Password );      
    }
    else
      Thread.Sleep(10); //nothing received, sleep sometime
  }
}

Consideration of background application

Although the request won't be lost in pop3 queue if Receive method isn't invoked. To obtain higher performance, background application should have the ability to serve for multiple concurrent requests. As such, multiple-threading background application is strongly recommended. For details, please refer to POP3QUEUE sample in ANPOP installation package. It demonstrates a multiple-threading background application which works with multiple pop3 accounts concurrently.

Free Email Support

Not enough? Please contact our technical support team.

Support@EmailArchitect.NET
VIP@EmailArchitect.NET (Registered User)

Remarks
We usually reply emails in 24hours. The reason for getting no response is likely that your smtp server bounced our reply. In this case, please try to use another email address to contact us. Your Hotmail or Yahoo email account is recommended.



2001-2010 © Copyright AdminSystem Software Limited. All rights reserved.   About us  Site Map