Hi Friends,
For the first time iam posting my problem,
Iam trying to read Email Programmatically using IMAP setting its is console
using System.Collections.Generic;
using System.Text;
namespace EmailConsole
{
class Program
{
static System.IO.StreamWriter sw = null;
static System.Net.Sockets.TcpClient tcpc = null;
static System.Net.Security.SslStream ssl = null;
static string username, password;
static string path;
static int bytes = -1;
static byte[] buffer;
static StringBuilder sb = new StringBuilder();
static byte[] dummy;
static void Main(string[] args)
{
try
{
path = @"D:\emailresponse.txt";
if (System.IO.File.Exists(path))
System.IO.File.Delete(path);
sw = new System.IO.StreamWriter(System.IO.File.Create(path));
tcpc = new System.Net.Sockets.TcpClient("", );
ssl = new System.Net.Security.SslStream(tcpc.GetStream());
ssl.AuthenticateAsClient("outlook.office365.com");
receiveResponse("");
Console.WriteLine("username : ");
username = Console.ReadLine();
Console.WriteLine("password : ");
password = Console.ReadLine();
receiveResponse("$ LOGIN " + username + " " + password + " \r\n");
Console.Clear();
receiveResponse("$ LIST " + "\"\"" + " \"*\"" + "\r\n");
receiveResponse("$ SELECT INBOX\r\n");
receiveResponse("$ STATUS INBOX (MESSAGES)\r\n");
Console.WriteLine("enter the email number to fetch :");
int number = int.Parse(Console.ReadLine());
receiveResponse("$ FETCH " + number + " body[header]\r\n");
receiveResponse("$ FETCH " + number + " body[text]\r\n");
receiveResponse("$ LOGOUT\r\n");
}
catch (Exception ex)
{
Console.WriteLine("error: " + ex.Message);
}
finally
{
if (sw != null)
{
}
if (ssl != null)
{
}
if (tcpc != null)
{
}
}
Console.ReadKey();
}
static void receiveResponse(string command)
{
try
{
if (command != "")
{
if (tcpc.Connected)
{
dummy = Encoding.ASCII.GetBytes(command);
ssl.Write(dummy, 0, dummy.Length);
}
else
{
throw new ApplicationException("TCP CONNECTION DISCONNECTED");
}
}
ssl.Flush();
buffer = new byte[2048];
bytes = ssl.Read(buffer, 0, 2048);
sb.Append(Encoding.ASCII.GetString(buffer));
Console.WriteLine(sb.ToString());
sw.WriteLine(sb.ToString());
sb = new StringBuilder();
}
catch (Exception ex)
{
throw new ApplicationException(ex.Message);
}
}
}
}
But iam getting repeatedly following error :
Unable to write data to the transport connection: An established connection was aborted by the software in your host machine.
What I have tried:
when I searched I found following ideas,
That's most likely due to some underlying proxy system closing your connection.
something on your machine is blocking your connection. Try running it with firewall/antivirus disabled. This is not permanent, just for testing if this is setup issue or code issue. If it passes without the firewall/antivirus then you have to find a way to allow it through them - add it to the firewall exceptons, etc.
problem solved when disabled the antivirus
I have tried with these ideas but still the error was not fixed. Kindly Help me.
Thanks in advance.