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:
hello,

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

Thanks & Regards,
Sumit Garg

What I have tried:

string Mailserver = "imap.abc.com";
string MailServerPort = "993";
string MailServerUsername = "sumit@abc.com";
string MailServerPwd = "Password";
var client = new ImapX.ImapClient("imap.abc.com", 993, true);
client.Connect();
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.
Posted
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.
C#
string Mailserver = "imap.abc.com";
int MailServerPort = 993;          // why set this as a string to convert back later?
string MailServerUsername = "sumit@abc.com";
string MailServerPwd = "Password";

try {
  var client = new ImapX.ImapClient("imap.abc.com", 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
}

Documentation
https://imapx.org/docs/wikipage%20(1).html[^]
 
Share this answer
 
Comments
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