コード例 #1
0
ファイル: Program.cs プロジェクト: lcssk8board/email-checker
        static async Task<EmailInfo> CheckEmailAddresses(
            string email,
            string mxHostAddress,
            int port,
            ProgressBar pbar
        )
        {
            pbar.Tick($"Currently processing: #{pbar.CurrentTick} emails searched...");

            var mailInfo = new EmailInfo
            {
                Email = email,
                ProviderExists = false,
                EmailResolution = EmailResolutionType.CantDetemine
            };

            try
            {
                if (!string.IsNullOrEmpty(mxHostAddress) && !string.IsNullOrEmpty(email))
                {
                    using (var telnetClient = new Client(
                        mxHostAddress,
                        port,
                        CancellationToken.None
                    ))
                    {
                        if (mailInfo.ProviderExists = telnetClient.IsConnected)
                        {
                            mailInfo.Email = email;
                            await telnetClient.Write("HELO localhost\r\n");
                            await telnetClient.ReadAsync(new TimeSpan(0, 0, 10));

                            await telnetClient.Write("MAIL FROM:<*****@*****.**>\r\n");
                            await telnetClient.ReadAsync(new TimeSpan(0, 0, 10));

                            await telnetClient.Write(
                                string.Format("RCPT TO:<{0}>\r\n", email)
                            );

                            var response = await telnetClient.ReadAsync(new TimeSpan(0, 1, 0));

                            if (response.StartsWith("2"))
                                mailInfo.EmailResolution = EmailResolutionType.Exist;
                            else if (response.StartsWith("5") && response.Contains("exist"))
                                mailInfo.EmailResolution = EmailResolutionType.NotExist;
                            else
                                mailInfo.EmailResolution = EmailResolutionType.CantDetemine;
                        }

                        await telnetClient.Write("QUIT");
                    }
                }
            }
            catch (Exception ex)
            {
                _log.Error(string.Empty, ex);
            }

            return mailInfo;
        }
コード例 #2
-2
 public static void SendMessage()
 {
     using (var client = new Client ("192.168.123.111", 10000, new System.Threading.CancellationToken ())) {
         if (client.IsConnected) {
             var s = new StringBuilder ();
             s.Append ("Datum: " + DateTime.Now.ToShortDateString () + "\n");
             s.Append ("Uhrzeit: " + DateTime.Now.ToLongTimeString () + "\n");
             s.Append ("Status: " + "EIN" + "\n");
             s.Append ("Meldung: " + "Ich bin eine einfache Meldung" + "\n");
             s.Append ("55A2A7A9");
             client.Write (s.ToString ());
         }
     }
 }