Get Gmail folder structures using IMAP

Hi

I am using Aspose to get Gmail folders using IMAP. I used the following settings:

url: imap.gmail.com

use SSL: true

port: 993

About one or two weeks ago, when I do get folders, I got a result which is visualized in GmailOld.png. Some Gmail folders are prefixed by [Gmail] and shows in [Gmail] subfolder. Although this is different from what I see in google chrome, I do not mind because all the folders are there and no customer complained.

However, today I got a result which is visualized in GmailNew.png. I got an extra “/” root folder, and the [Gmail] folder does not have subfolders. This is unacceptable because there is no way to access some folders like “Drafts”.

could you please let me know what is going on? I am using aspose.email version 2.4.0.0. below is part of my code snippet, where client is a ImapClient instance.

ImapFolderInfoCollection folderInfos = client.ListFolders();

folderInfos.ToList().ForEach(info=>client.ListFolders(info.Name));

Thanks.

Hi Xu,


We are sorry for the inconvenience caused.

The issue of ImapClient functionality with gmail arose few days back and is already logged in our issue tracking system for resolution by the development team. We are planning to release a hot fix version as soon as the issue is rectified. Please spare us a little time until we get back to you in this regard.

Hi Xu,


Please download the hot fix version of Aspose.Email for .NET 3.2.1, where the issues related to Gmail have been fixed, and let us know your feedback.

Hi


Thanks for your feedback. I downloaded it and it fixed my gmail problem with IMAP. However, it seems broke EWS exchange server.

I have an EWS Exchange server, which I can get folder and emails using Aspose.Email, version 2.4.0.0. Now I got the following exception when I try to call client.GetMailboxInfo(), where client is an ExchangeWebServiceClient. Could you please take a look? Thanks.


System.Net.WebException was caught
HResult=-2146233079
Message=The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
Source=System.Web.Services
StackTrace:
at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at Aspose.Email.Exchange.Schema.ExchangeServiceBinding.GetFolder(GetFolderType GetFolder1)
at Aspose.Email.Exchange.ExchangeWebServiceClient.GetMailboxInfo(String mailbox, Int64& mailboxSize)
at Aspose.Email.Exchange.ExchangeWebServiceClient.GetMailboxInfo()
at Aspose.Email.Exchange.ExchangeWebServiceClient.GetMailboxInfo(String mailbox)
at KnowledgeLake.Capture.Server.Import.ImportSourceEmail.Exchange.ExchangeServiceModel.GetExchangeServerType(ExchangeClientConfig config, String plainPassword) in c:\Code\Import Server 5.x (Scrum)\ImportServer\KnowledgeLake.Capture.Server.Import.ImportSourceEmail\Exchange\ExchangeServiceModel.cs:line 244
InnerException: System.Security.Authentication.AuthenticationException
HResult=-2146233087
Message=The remote certificate is invalid according to the validation procedure.
Source=System
StackTrace:
at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)
at System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.Net.ConnectStream.WriteHeaders(Boolean async)
InnerException:

Hi Xu,

I am afraid but I am unable to reproduce this issue at my end with the latest version of Aspose.Email for .NET 3.2.1 and my Exchange 2010 server. The following code sample lists the Mail box size and folders from my server without any exception. If it is possible for you to arrange a test account for us on your server, we’ll be able to investigate this issue at our end and assist you further.

Sample Code:

ExchangeWebServiceClient client = GetAsposeEWSClient();

// Get mailbox size
Console.WriteLine("Mailbox size: " + client.GetMailboxSize() + " bytes");

ExchangeFolderInfoCollection folders = client.ListSubFolders(client.GetMailboxInfo().RootUri);

foreach (ExchangeFolderInfo folder in folders)
    Console.WriteLine(folder.DisplayName);

may I see your GetAsposeEWSClient()


Thanks.

Hi Xu,

Here is my definition for getting EWS client to my exchange server:

Sample Code:

private static ExchangeWebServiceClient GetAsposeEWSClient()
{
    const string mailboxUri = "https://exchange-server-url/ews/Exchange.asmx";
    const string domain = @"";
    const string username = @"username";
    const string password = @"password";

    NetworkCredential credential = new NetworkCredential(username, password, domain);
    ExchangeWebServiceClient client = new ExchangeWebServiceClient(mailboxUri, credential);

    // Return the instance of ExchangeWebServiceClient class
    return client;
}

Hi

it still does not work. Below is my code snippet. Please let me know if I am doing anything wrong. This set of code works in Aspose.Email version 2.4.0.0

using (ExchangeWebServiceClient client = GetExchangeWebServiceClient(config, plainPassword))
{
client.GetMailboxSize();
return ExchangeServerType.EWS;
}

private ExchangeWebServiceClient GetExchangeWebServiceClient(ExchangeClientConfig config, string plainPassword)
{
…
ExchangeWebServiceClient client = new ExchangeWebServiceClient(“https://mail.CompanyName.com”, “userName”, “password”, “CompanyName.com”);
return client;
}

Hi Xu,

It seems that this error message appears if the Exchange Server has a self signed SSL certificate or it is expired. Please use the following approach (as mentioned HERE) and let us know your feedback:

// register callback method for SSL validation event in main() or init()

ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidationHandler;

// this event handler will be called when SSL certificate is verified

private static bool RemoteCertificateValidationHandler(object sender, X509Certificate certificate, X509Chain chain,SslPolicyErrors sslPolicyErrors)

{

return true; //ignore the checks and go ahead

}