Provides properties and methods for receiving messages and managing IMAP4 folder.
System.Object
EAGetMail.MailClient
[Visual Basic] Public Class MailClient
[C#] public class MailClient
[C++] public __gc class MailClient
[JScript] public class MailClient
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Public Constructors
| MailClient Constructor | Initializes a new instance of the MailClient class. |
Public Properties
| ClientCertificate | The certificate to enable the SSL connection. |
| Connected | Gets whether the server is connected. |
| Conversation | Gets the latest conversation beween mail server and mail client. |
| CurrentMailServer | Gets the latest mail server that is used to receive e-mail message. |
| Imap4Folders | Gets the folders on IMAP4 server. |
| LogFileName | Gets or sets the log file name for mail transaction. |
| SelectedFolder | Gets the current selected folder of IMAP4 server. |
| Tag |
Gets or sets an object that contains data to associate with the MailClient. |
| Timeout |
Gets or sets the maximum time interval(seconds) the object will wait for a response from server before returning an error. |
Public Methods
| Append | Appends an email to specified IMAP4 folder. |
| AppendEx | Appends an email to specified IMAP4 folder with flags. |
| ChangeMailFlags | Changes the flags of an email on IMAP4 server. |
| Close | Closes the connection to server forcely. |
| Connect | Connects a mail server. |
| Copy | Copies a specified email from selected folder to another folder on IMAP4 server. |
| CreateFolder | Creates an IMAP4 folder on IMAP4 server. |
| Delete | Marks the specified email as deleted. |
| DeleteFolder | Removes the specified IMAP folder from IMAP4 server. |
| Expunge | Pures the deleted emails in current selected folder on IMAP4 server. |
| GetMail | Receives a specified email from mail server. |
| GetMailHeader | Receives a specified email headers from mail server. |
| GetMailInfos | Retrieves all emails' information on mail server. |
| Logout | Disconnects with IMAP4 server without expunging the deleted emails. |
| Quit | Disconnects the mail server and expunging the deleted emails. |
| Reset | Undeletes the deleted emails on mail server. |
| SelectFolder | Selects an IMAP4 folder to operate. |
| SubscribeFolder | Subscribes an IMAP4 folder. |
| UnsubscribeFolder | Unsubscribes an IMAP4 folder. |
Public Events
| OnAuthorized | Occurs when mail server has authorized the user. |
| OnConnected | Occurs when the client has connected to mail server successfully. |
| OnIdle | Occurs when the client is connecting server or waiting response from mail server. |
| OnQuit | Occurs when the client is disconnecting the mail server. |
| OnReceiveResponse | Occurs when the client has received a response from mail server. |
| OnReceivingDataStream | Occurs when the client is receiving the e-mail data from mail server. |
| OnSecuring | Occurs when the client is establishing the SSL connection. |
| OnSendCommand | Occurs when the client has sent a command to the mail server. |
| OnSendingDataStream | Occurs when the client is sending the e-mail data (Append) to the IMAP4 server. |
Example
[Visual Basic, C#, C++] The following example demonstrates how to receive email with EAGetMail POP3 & IMAP Component, but it doesn't demonstrates the events and mail parsing usage. To get the full samples of EAGetMail, please refer to Samples section.
[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
oClient.Connect(oServer)
Dim infos() As MailInfo = oClient.GetMailInfos()
Dim count As Integer = infos.Length
For i As Integer = 0 To count - 1
Dim info As MailInfo = infos(i)
Console.WriteLine( "UIDL: {0}", info.UIDL )
Console.WriteLine( "Index: {0}", info.Index )
Console.WriteLine( "Size: {0}", info.Size )
'For POP3 server, the IMAP4MailFlags is meaningless.
Console.WriteLine( "Flags: {0}", info.IMAP4MailFlags )
Dim oMail As Mail = oClient.GetMail(info)
''Save mail to local file
oMail.SaveAs(String.Format("c:\{0}.eml", i), True)
Next
For i As Integer = 0 To count - 1
Dim info As MailInfo = infos(i)
oClient.Delete(info)
Next
'
' Delete method just mark the email as deleted,
' Quit method pure the emails from server exactly.
oClient.Quit()
Catch ep As MailServerException
''Message contains the information returned by mail server
Console.WriteLine("Server Respond: {0}", ep.Message)
Catch ep As System.Net.Sockets.SocketException
Console.WriteLine("Socket Error: {0}", ep.Message)
Catch ep As Exception
Console.WriteLine("System Error: {0}", ep.Message)
End Try
' show the conversation between server and client.
Console.WriteLine( oClient.Conversation )
oClient.Close()
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
{
oClient.Connect(oServer);
MailInfo [] infos = oClient.GetMailInfos();
int count = infos.Length;
for( int i = 0; i < count; i++ )
{
MailInfo info = infos[i];
Console.WriteLine( "UIDL: {0}", info.UIDL );
Console.WriteLine( "Index: {0}", info.Index );
Console.WriteLine( "Size: {0}", info.Size );
//For POP3 server, the IMAP4MailFlags is meaningless.
Console.WriteLine( "Flags: {0}", info.IMAP4MailFlags );
Mail oMail = oClient.GetMail(info);
//Save mail to local file
oMail.SaveAs(String.Format("c:\\{0}.eml", i), true);
}
for( int i = 0; i < count; i++ )
{
MailInfo info = infos[i];
oClient.Delete(info);
}
// Delete method just mark the email as deleted,
// Quit method pure the emails from server exactly.
oClient.Quit();
}
catch( MailServerException ep )
{
//Message contains the information returned by mail server
Console.WriteLine("Server Respond: {0}", ep.Message);
}
catch( System.Net.Sockets.SocketException ep )
{
Console.WriteLine("Socket Error: {0}", ep.Message);
}
catch( Exception ep )
{
Console.WriteLine("System Error: {0}", ep.Message);
}
// show the conversation between server and client.
Console.WriteLine( oClient.Conversation );
oClient.Close();
}
[C++]
using namespace System;
using namespace System::Collections;
using namespace EAGetMail;
Void ReceiveMail(
String *sServer,
String *sUserName,
String *sPassword,
bool bSSLConnection)
{
MailClient *oClient = new MailClient(S"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-> = S"c:\\pop.log";
try
{
oClient->Connect(oServer);
MailInfo *infos[]= oClient->GetMailInfos();
int count = infos->Length;
for( int i = 0; i < count; i++ )
{
MailInfo *info = infos[i];
Console::WriteLine( "UIDL: {0}", info->UIDL );
Console::WriteLine( "Index: {0}", __box(info->Index));
Console::WriteLine( "Size: {0}", __box(info->Size));
//For POP3 server, the IMAP4MailFlags is meaningless.
Console::WriteLine( "Flags: {0}", info->IMAP4MailFlags );
Mail *oMail = oClient->GetMail(info);
//Save mail to local file
oMail->SaveAs(String::Format(S"c:\\{0}.eml", __box(i)), true);
}
for( int i = 0; i < count; i++ )
{
MailInfo *info = infos[i];
oClient->Delete(info);
}
// Delete method just mark the email as deleted,
// Quit method pure the emails from server exactly.
oClient->Quit();
}
catch( MailServerException *ep )
{
//Message contains the information returned by mail server
Console::WriteLine( S"Server Respond: {0}", ep->Message);
}
catch( System::Net::Sockets::SocketException *ep )
{
Console::WriteLine( S"Socket Error: {0}", ep->Message);
}
catch( Exception *ep )
{
Console::WriteLine( S"System Error: {0}", ep->Message);
}
// show the conversation between server and client.
Console::WriteLine( oClient->Conversation );
oClient->Close();
}