hello every one
i'm trying to send emails via my application
i used smtp, but it throw exception
someone told me to login using pop3 first, but it throws the exception
"'220 servername ESMTP"
here is my code
static void DoPopAuth(string host, string user, string passphrase)
{
TcpClient cli = new TcpClient();
cli.ReceiveTimeout = TimeoutMs;
cli.SendTimeout = TimeoutMs;
cli.Connect(host, 587);
using (Stream peer = cli.GetStream())
{
StreamWriter wtr = new StreamWriter(peer); // ASCII?
Debug.Assert("\x000D\x000A" == wtr.NewLine, "CRLF!");
StreamReader rdr = new StreamReader(peer); // ASCII?
String line;
//
line = rdr.ReadLine();
if (line == null)
throw new EndOfStreamException("Closed by peer at: Connect");
Debug.WriteLine("Received: '{0}'", line);
if (!line.StartsWith(SuccessCode, StringComparison.Ordinal))
throw new InvalidOperationException("Error at connect: '" + line + "'");
// TODO check if host supports APOP. Regex(".*{<.*@.*>}");
//
wtr.WriteLine("USER {0}", user);
wtr.Flush();
line = rdr.ReadLine();
if (line == null)
throw new EndOfStreamException("Closed by peer at: USER");
Debug.WriteLine("Received: '{0}'", line);
if (!line.StartsWith(SuccessCode, StringComparison.Ordinal))
throw new InvalidOperationException("Error on USER: '" + line + "'");
//
wtr.WriteLine("PASS {0}", passphrase);
wtr.Flush();
line = rdr.ReadLine();
if (line == null)
throw new EndOfStreamException("Closed by peer at: PASS");
Debug.WriteLine("Received: '{0}'", line);
if (!line.StartsWith(SuccessCode, StringComparison.Ordinal))
throw new InvalidOperationException("" + line + "'");
// If we got here success!
}
}
and i call this method here
DoPopAuth("mail1.dnsegypt.net", "mymail", "mypass");
any help would be apprecited