关于TCPClient验证Email是否存在的问题

zj25810 zj25810 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
最近在做一个EDM客户端,需求上有一个点击批量发邮件的。
然后后台需要添加一条是否发送成功的数据,就类似于一个日志的东西吧。
真心没弄过,这次连winform都算是第一次接触,各种为难。
网上找资料,找到了一套这样的写法。

private void SendEmail(){
string _smtp = "b2bmail1.bjx.com.cn";

IPHostEntry hostEntry = Dns.GetHostEntry(_smtp);
IPEndPoint endPoint = new IPEndPoint(hostEntry.AddressList[0], 25);
using (TcpClient tcpc = new TcpClient())
{
tcpc.Connect(endPoint);

if (OperaStream(tcpc, "MAIL FROM:" + _smtp) != "250")
{
Success = "MAIL命令不能完成,SMTP服务需要验证";
OperaStream(tcpc, "QUIT");
}
if (OperaStream(tcpc, "RCPT TO: " + item.Email) != "250")//这边的item.Email,我代入了两个值,一个自己的QQ邮箱,一个1@qq.com(这个邮箱在QQ邮箱里发件是验证了此邮箱无效的)。
{
Success = item.Email + "此邮件地址并非有效";
OperaStream(tcpc, "QUIT");
}
}
}


public string OperaStream(TcpClient tcpc, string strCmd)
{
try
{
Stream TcpStream;
strCmd = strCmd + "/r/n";
TcpStream = tcpc.GetStream();
byte[] bWrite = Encoding.Default.GetBytes(strCmd.ToCharArray());
TcpStream.Write(bWrite, 0, bWrite.Length);
StreamReader sr = new StreamReader(tcpc.GetStream(), Encoding.Default);
string rl = sr.ReadLine();
string sp = rl.Substring(0, 3);
return sp;

}
catch (Exception ex)
{

throw;
}
}

不管我的item.Email是不是有效邮件地址,return sp;的返回值都是220,220到底是什么意思?求教育。

...全文

相关推荐

C#验证Email是否真正存在

在以往的编程中,比如编写用户的资料时,有时需要确认用户输入的Email是否真实有效,以前我们最多只能做到验证Email是否包含了某些特殊的字符,比如"@",".",".com"等,做到的只是判断了 Email的合法性,证明用户填写的Email格式是正确的,但是这个Email是否真正的存在于网络中,则没有办法。  首先需要大家了解一下SMTP协议。

a1052332559

C#编写发送Emai邮件

C#编写发送Emai邮件

a200606142

tcpclient-server.rar_TCPClient_world

Tcp client server communication using Java The client–server model is a distributed application structure that partitions tasks or workloads between the providers of a resource or service, called servers, and service requesters, called clients.[1] Often clients and servers communicate over a computer network on separate hardware, but both client and server may reside in the same system. A server host runs one or more server programs which share their resources with clients. A client does not share any of its resources, but requests a server s content or service function. Clients therefore initiate communication sessions with servers which await incoming requests. Examples of computer applications that use the client–server model are Email, network printing, and the World Wide Web

weixin_42653672

VisualC#网络编程.pdf

VisualC#网络编程.pdf

资料大全

socket网络编程

socket编写的远程控制端和一些远程控制的技术

liuxunixin
评论 7
收藏 已收藏
分享
返回顶部
zj25810
.NET社区 62,275 成员 668,967 内容