Private Function GetMailServer(ByVal sDomain As String) As String Dim info As New ProcessStartInfo() Dim ns As Process '调用Windows的nslookup命令,查找邮件服务器 info.UseShellExecute = False info.RedirectStandardInput = True info.RedirectStandardOutput = True info.FileName = "nslookup" info.CreateNoWindow = True '查找类型为MX。关于nslookup的详细说明,请参见 'Windows帮助 info.Arguments = "-type=MX " + sDomain.ToUpper.Trim '启动一个进行执行Windows的nslookup命令() ns = Process.Start(info) Dim sout As StreamReader sout = ns.StandardOutput ' 利用正则表达式找出nslookup命令输出结果中的邮件服务器信息 Dim reg As Regex = New Regex("mail exchanger = (?[^///s]+)") Dim mailserver As String Dim response As String = "" Do While (sout.Peek() > -1) response = sout.ReadLine() Dim amatch As Match = reg.Match(response) If (amatch.Success) Then mailserver = amatch.Groups("server").Value Exit Do End If Loop Return mailserver End Function
Public Function CheckEmail(ByVal sEmail As String) As Long
Dim oStream As NetworkStream Dim sFrom As String '发件人 Dim sTo As String '收件人 Dim sResponse As String '邮件服务器的应答 Dim Remote_Addr As String '发件人的域名 Dim mserver As String '邮件服务器 Dim sText As String()
sTo = "<" + sEmail + ">" ' 从邮件地址分离出帐户名和域名 sText = sEmail.Split(CType("@", Char)) ' 查找该域的邮件服务器 mserver = GetMailServer(sText(1)) 'mserver为空值表明查找邮件服务器失败 If mserver = "" Then Return 4 Exit Function End If '发件人地址的域名必须合法 Remote_Addr = "sina.com.cn" sFrom = "