Error while Connecting to Gmail Account
AE_2_1_0002 NO [AUTHENTICATIONFAILED] Invalid credentials (Failure)
This is the error I’m getting while trying to connect to Gmail Account using Imap Server
Following is the code, Please tell me the problem in the code and the way to connect to Gmail Account using Imap Server
string username = textBox1.Text.ToString().Trim();
string password = textBox2.Text.ToString().Trim();
//Aspose.Email.Clients.Imap.ImapClient imap = new Aspose.Email.Clients.Imap.ImapClient("imap.gmail.com", 993, "xxxx@gmail.com", "pas");
try
{
// connect to gmail server
ImapClient client = new ImapClient();
// client.CreateConnection();
client.UseDefaultCredentials = false;
client.Host = "imap.gmail.com";
client.Port = 993;
client.Username = username;
client.Password = password;
client.EnableSupported = true;
client.SecurityOptions = SecurityOptions.SSLImplicit;
// Select the inbox folder and Get the message info collection
try
{
// ExStart:GettingFoldersInformation
// Get all folders in the currently subscribed folder
ImapFolderInfoCollection folderInfoColl = client.ListFolders();
// Iterate through the collection to get folder info one by one
foreach (ImapFolderInfo folderInfo in folderInfoColl)
{
// Folder name and get New messages in the folder
MessageBox.Show("Folder name is " + folderInfo.Name);
ImapFolderInfo folderExtInfo = client.GetFolderInfo(folderInfo.Name);
MessageBox.Show("New message count: " + folderExtInfo.NewMessageCount);
MessageBox.Show("Is it readonly? " + folderExtInfo.ReadOnly);
MessageBox.Show("Total number of messages " + folderExtInfo.TotalMessageCount);
}
// ExEnd:GettingFoldersInformation
// Disconnect to the remote IMAP server
client.Dispose();
}
catch (Exception ex)
{
MessageBox.Show("Error while creating Folders"+ Environment.NewLine+ex.Message);
}
MessageBox.Show(Environment.NewLine + "Getting folders information from IMAP server.");
MessageBox.Show("done");
}
catch(Exception ex)
{
MessageBox.Show("Error while connecting to Gmail Account"+Environment.NewLine+ex.Message);
}
Please help me to resolve the issue.