2015年12月22日 星期二

VB.NET驗證郵件地址的合法性實現代碼

參考引用來源:VB.NET驗證郵件地址的合法性實現代碼
--
1. nslookup -type=mx  gmail.com

2.
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

沒有留言:

張貼留言