C# la txt dosyasından yada web sayfasından eposta yakalama/ayıklama

Haz 21 2011 Published by under c#

Verilen dosya içindeki epostaları yakalayıp başka bir txt dosyasına yazan kodlar

            string okunacak_txt=@"c:\oku.txt";
            string yazilacak_txt = @"c:\yaz.txt";
            string data = File.ReadAllText(okunacak_txt);
            Regex emailRegex = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", RegexOptions.IgnoreCase);
            MatchCollection emailMatches = emailRegex.Matches(data);
            StringBuilder sb = new StringBuilder();
            foreach (Match emailMatch in emailMatches)
            {
                sb.AppendLine(emailMatch.Value + Environment.NewLine);
            }
            File.WriteAllText(yazilacak_txt, sb.ToString());

Aynı şekilde istenirse txt dosyadan okumak yerine websitesi içerisinden okuma yapılabilir.


        WebClient w = new WebClient();
        w.Encoding = System.Text.Encoding.UTF8;
        string s = w.DownloadString("http://www.tiravoglu.com");
        string yazilacak_txt = @"c:\yaz.txt";
        string data = s;
        Regex emailRegex = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", RegexOptions.IgnoreCase);
        MatchCollection emailMatches = emailRegex.Matches(data);
        StringBuilder sb = new StringBuilder();
        foreach (Match emailMatch in emailMatches)
        {
            sb.AppendLine(emailMatch.Value + Environment.NewLine);
        }
        File.WriteAllText(yazilacak_txt, sb.ToString());

No responses yet