Work with EAGetMail Service


EAGetMail Service is an advanced service which can download emails from POP3/IMAP4 servers in background. It provides many features such as retrieving and saving emails to specified folders in schedule, and starting a specified application to handle downloaded emails.

This service facilitates EAGetMail POP3/IMAP4 Component developers that their applications can now accept an email retrieving request from EAGetMail Application, and then download emails in background. This is particularly useful for ASP/ASP.NET web application.

Retrieve emails in background

In an ASP/ASP.NET email application, if email download takes longer than the timeout 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 via 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.

EAGetMail Component introduces a more intelligent method to retrieve emails in background. You should download the EAGetMail Service installer and install it on your machine at first. Then you can use MailClient.GetMailsByQueue method to send the request to EAGetMail Service, the method returns to the user immediately and the EAGetMail Service performs task in background.

Example

[Visual Basic]
Imports EAGetMail

Public Sub ReceiveMail( _
ByVal sServer As String, _
ByVal sUserName As String, _
ByVal sPassword As String, _
ByVal bSSLConnection As Boolean)
    Dim oClient As New MailClient("TryIt")
    'To receive email from imap4 server, please change
    'ServerProtocol.Pop3 to ServerProtocol.Imap4 in MailServer constructor

    Dim oServer As New MailServer(sServer, _
        sUserName, sPassword, bSSLConnection, _
        ServerAuthType.AuthLogin, ServerProtocol.Pop3)

    'by default, the pop3 port is 110, imap4 port is 143, 
    'the pop3 ssl port is 995, imap4 ssl port is 993
    'you can also change the port like this
    'oServer.Port = 110
    
    ' generates a log file
    ' oClient.LogFileName = "c:\pop.log"
    
    Try
        Dim leaveCopy As Boolean = True 'leave a copy of message on server.
        Dim downloadFolder As String = "c:\popdownload" 'download emails to this local folder.
        'send request to EAGetMail Service, then EAGetMail Service retrieves email in background and 
        'this method returns immediately.
        oClient.GetMailsByQueue(oServer, downloadFolder, leaveCopy )
       
    Catch ep As Exception
        Console.WriteLine("Error: {0}", ep.Message)
    End Try
End Sub    

[C#]
using System;
using System.Collections;
using EAGetMail;

public void ReceiveMail( 
    string sServer, 
    string sUserName,
    string sPassword,
    bool bSSLConnection)
{
    MailClient oClient = new MailClient("TryIt");
    //To receive email from imap4 server, please change
    //ServerProtocol.Pop3 to ServerProtocol.Imap4 in MailServer constructor

    MailServer oServer  = new MailServer(sServer, 
        sUserName, sPassword, bSSLConnection, 
        ServerAuthType.AuthLogin, ServerProtocol.Pop3);

    //by default, the pop3 port is 110, imap4 port is 143, 
    //the pop3 ssl port is 995, imap4 ssl port is 993
    //you can also change the port like this
    //oServer.Port = 110;
    
    // generates a log file
    // oClient.LogFileName = "c:\\pop3.log";
    
    try
    {
         bool leaveCopy = true; //leave a copy of message on server.
         string downloadFolder =  "c:\\popdownload"; //download emails to this local folder
        //send request to EAGetMail Service, then EAGetMail Service retrieves email in background and 
        //this method returns immediately.
        oClient.GetMailsByQueue(oServer, downloadFolder, leaveCopy );
    }
    catch( Exception ep ) 
    {
        Console.WriteLine("Error: {0}", ep.Message);
    }
}

Retrieve emails in schedule

EAGetMail Service provides another advanced feature which allow you set a POP3/IMAP4 account in the EAGetMail Service Manager. EAGetMail Service can download emails from this account in specified time interval. If you need to process the email in the mailbox in schedule, you just need to create your mail process application, you don't need to write your email download task part. Finally you just need to set your mail account in EAGetMail Service Manager and specify your application or COMMAND, EAGetMail service will download the emails and invoke your application automatically. Please refer to Mail Pull for more detail.

See Also

Using EAGetMail POP3 & IMAP4 Component
User Authentication and SSL Connection
Digital Signature and E-mail Encryption/Decryption
Parse Bounced Email (delivery-report)
Work with winmail.dat (TNEF Parser)
EAGetMail Namespace References
EAGetMail POP3 & IMAP4 Component Samples