Click here to Skip to main content
15,922,315 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:

I have an Outlook account like company name abc and Outlook id is and i want to integration using c# for send and receive mail by IMAP.

Thanks & Regards,
Sumit Garg

What I have tried:

string Mailserver = "";
string MailServerPort = "993";
string MailServerUsername = "";
string MailServerPwd = "Password";
var client = new ImapX.ImapClient("", 993, true);
client.Login(MailServerUsername, MailServerPwd);

ImapClient imap = new ImapClient(Mailserver, Convert.ToInt32(MailServerPort), true);
imap.IsDebug = true;
ImapClient imapClient;
int count = client.Folders.Inbox.Messages.Count();

its showing zero count.
Updated 8-Apr-19 1:25am

1 solution

I would try running this in DEBUG with some IF...THEN & TRY...CATCH blocks as well as some Breakpoints to see what path you are actually following.
string Mailserver = "";
int MailServerPort = 993;          // why set this as a string to convert back later?
string MailServerUsername = "";
string MailServerPwd = "Password";

try {
  var client = new ImapX.ImapClient("", 993, true);

  if (!client.Connect()) {
    // Connection Failed ==> TODO: Figure out why
  } else {
    // We connected.... Now lets try to login

    if (!client.Login(MailServerUsername, MailServerPwd)) {
      // Login failed ==> TODO: Figure out why
    } else {
      // continue with your code, using similar techniques
} catch (Exception ex) {
  // TODO:  Analyze EX and work from there

Share this answer
alexcoder99 9-Apr-19 11:04am    
When diagnosing any email connectivity related issues I find using Telnet to query the email server using the same credentials at the network level a really useful technique to identify any errors; once I have connectivity using Telnet its often just a case of building a connection using the same configuration in code

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900