I have to read an inbox (Inbox Outlook Microsoft Exchange) of an email, I have the email account, the password and by the mail server I have the host (the email is configured as SMTP NOT POP3 or IMAP ) and the port.
This is my code
private void connection()
{
try
{
using (ImapClient client = new ImapClient("smtp.miempresa.com", 25, "[email protected]", "mipasswaor", AuthMethod.Login, false))
{
if (client.Supports("IDLE") == false)
{
MessageBox.Show("El servidor no soporta IMAP IDLE");
}
client.NewMessage += new EventHandler<IdleMessageEventArgs>(OnNewMessage);
}
}
catch (System.Exception ex)
{
MessageBox.Show("Error no controlado:\n"+ex.Message,"Error");
}
}
static void OnNewMessage(object sender, IdleMessageEventArgs e)
{
MessageBox.Show("Mensaje nuevo recibido");
MailMessage m = e.Client.GetMessage(e.MessageUID, FetchOptions.Normal);
f.Invoke((MethodInvoker)delegate
{
f.richTextBox1.AppendText("From: " +m.From + "\n"+
"Subject: " +m.Subject+"\n"+
"Body: "+ m.Body+"\n"+
"Attach: "+m.Attachments+"\n");
});
}
With this code, what I want is to show in a RichTextBox
the emails in the tray, but when I try to connect it produces the following error:
220 SMT-KMCI2004.mycompany.com Microsoft ESMTP MAIL Service ready at Wed, 5 Sep 2018 14:40:40 -0400
Any idea of the error, or any other way of reading Microsoft Exchange emails?