C#处理来自邮件服务器的TELNET响应 [英] C# handle TELNET response from mail server

查看:69
本文介绍了C#处理来自邮件服务器的TELNET响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想编写一个应用程序来检测是否存在电子邮件。这里的步骤:

步骤1. telnet mta7.am0.yahoodns.net 25 //连接到雅虎邮件服务器

步骤2. EHLO hi //说helo

步骤3.邮件来自:< test@gmail.com> //检查发件人

步骤4. rcpt:< lisa@yahoo.com> //检查接收器



但是我只得到了STEP 1的响应。错过了步骤2,3,4的响应。



我只在下面得到了这个回复(步骤1):

Hi everyone,
I want to code a application to detect email exist or not. Steps here:
STEP 1. telnet mta7.am0.yahoodns.net 25 // connect to yahoo mail server
STEP 2. EHLO hi // say helo
STEP 3. mail from: <test@gmail.com> // check sender
STEP 4. rcpt to: <lisa@yahoo.com> // check receiver

But I only got response of STEP 1. And missed response from STEP 2,3,4.

I only got this response below (step 1):

220 mta4051.mail.gq1.yahoo.com ESMTP ready





请给我一个解决方案。非常感谢!



我的尝试:



我的代码:



Please give me a solution. Many thanks!

What I have tried:

My code:

static void Main(string[] args)
        {
            TcpClient tcpClient;
            NetworkStream networkStream;
            StreamWriter streamWriter;

            tcpClient = new TcpClient("mta7.am0.yahoodns.net", 25);

            byte[] writeBuffer;
            byte[] readBuffer;
            using (networkStream = tcpClient.GetStream())
            {
                networkStream.Flush();

                writeBuffer = System.Text.Encoding.ASCII.GetBytes("EHLO hi" + Environment.NewLine);
                networkStream.Write(writeBuffer, 0, writeBuffer.Length);
                networkStream.Flush();

                writeBuffer = System.Text.Encoding.ASCII.GetBytes("mail from: <test@gmail.com>" + Environment.NewLine);
                networkStream.Write(writeBuffer, 0, writeBuffer.Length);
                networkStream.Flush();

                writeBuffer = System.Text.Encoding.ASCII.GetBytes("rcpt to: <lisa@yahoo.com>" + Environment.NewLine);
                networkStream.Write(writeBuffer, 0, writeBuffer.Length);
                networkStream.Flush();

                string output = null;

                if (networkStream.CanRead)
                {
                    readBuffer = new byte[tcpClient.ReceiveBufferSize];
                    networkStream.Read(readBuffer, 0, tcpClient.ReceiveBufferSize);

                    output = System.Text.Encoding.ASCII.GetString(readBuffer).Trim();
                    Console.WriteLine(output);
                }
                Console.ReadLine();
            }
        }

推荐答案

不要浪费你的时间,除非这是练习,这些天大多数邮件服务器不会报告电子邮件地址无效。



其次,谷歌c#tcpclient发送电子邮件smtp,你会找到如何做到这一点的例子,如理查德说你需要在处理响应后一次发送一个命令。



使用C#通过SMTP发送邮件 [ ^ ]
Don't waste your time unless this is for practice, these days most mail servers will not report that an email address is invalid.

Secondly, google "c# tcpclient send email smtp" and you'll find examples on how to do this, as Richard said you need to send the commands one at a time after processing the response.

Sending Mail Using C# via SMTP[^]


这篇关于C#处理来自邮件服务器的TELNET响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆