Beispiel #1
0
        public async Task RunScenario(List <LoginPasswordInput> listEmailAndPassword, string to, string subject, string[] emailText)
        {
            using (var browser = await PuppeteerBrowser.GetBrowser(_chromiumSettings.GetPath(), _chromiumSettings.GetHeadless()))
                foreach (var emailAndPassword in listEmailAndPassword)
                {
                    try
                    {
                        var login       = emailAndPassword.Login.Trim().ToLower();
                        var mailAddress = new MailAddress(login);
                        if (mailAddress != null)
                        {
                            if (MailRuDomains.Contains(mailAddress.Host))
                            {
                                using (var page = await browser.NewPageAsync())
                                {
                                    await page.GoToAsync(MailRuRegistration.GetLoginUrl());

                                    var isLoginSuccess = await MailRuRegistration.Login(accountName : login, password : emailAndPassword.Password, page : page);

                                    await MailRuRegistration.SendEmail(to : to, subject : subject, text : emailText, page : page);

                                    Info($"Почта отправлена {mailAddress.Address}");
                                }
                            }
                            if (mailAddress.Host.Equals(ServiceDomains.GetDomain(ServiceCode.Yandex)))
                            {
                                using (var page = await browser.NewPageAsync())
                                {
                                    await page.GoToAsync(YandexRegistration.GetLoginUrl());

                                    var isLoginSuccess = await YandexRegistration.Login(accountName : login, password : emailAndPassword.Password, page : page);

                                    await YandexRegistration.SendEmail(to : to, subject : subject, text : emailText, page : page);

                                    Info($"Почта отправлена {mailAddress.Address}");
                                }
                            }
                            if (mailAddress.Host.Equals(ServiceDomains.GetDomain(ServiceCode.Gmail)))
                            {
                                Info($"gmail {mailAddress.Address} {emailAndPassword.Password}");
                            }
                        }
                    }
                    catch (FormatException)
                    {
                        Error($"Некорректный адрес {emailAndPassword.Login}");
                    }
                }
        }
Beispiel #2
0
        public async Task <List <string> > RunScenario(string[] emails)
        {
            var result          = new List <string>();
            var listMailAddress = new Dictionary <string, MailAddress>(emails.Length);

            try
            {
                var dnsLite = new DnsLite();
                // https://developers.google.com/speed/public-dns/
                //http://www.opendns.com/opendns-ip-addresses/
                var dnslist = new List <string>
                {
                    "8.8.8.8",
                    "8.8.4.4",
                    "208.67.222.222",
                    "208.67.220.220"
                };

                var oldStyleList = new ArrayList();
                foreach (var s in dnslist)
                {
                    oldStyleList.Add(s);
                }
                dnsLite.setDnsServers(oldStyleList);

                foreach (var email in emails.Where(x => !string.IsNullOrEmpty(x)).Select(x => x.ToLower()).Distinct().ToArray())
                {
                    MailAddress mailAddress;
                    try
                    {
                        mailAddress = new MailAddress(email);
                    }
                    catch (FormatException)
                    {
                        mailAddress = null;
                    }

                    if (mailAddress != null)
                    {
                        if (EmailValidator.Validate(mailAddress.Address))
                        {
                            var servers = dnsLite.getMXRecords(mailAddress.Host).OfType <MXRecord>().OrderBy(record => record.preference).Select(x => "smtp://" + x.exchange).Distinct().ToList();
                            //var servers = dnsLite.getMXRecords(mailAddress.Host).OfType<MXRecord>().Distinct().ToList();
                            if (servers.Count > 0)
                            {
                                listMailAddress[mailAddress.Address] = mailAddress;
                                result.Add(mailAddress.Address);
                                Info($"{email} - успешная проверка написания");
                            }
                            else
                            {
                                Info($"{email} - ошибка Mx records");
                            }
                        }
                        else
                        {
                            Info($"{email} - ошибка rfc653x");
                        }
                    }
                    else
                    {
                        Info($"{email} - ошибка написания");
                    }
                }

                //проверка попыткой регистрации
                using (var browser = await PuppeteerBrowser.GetBrowser(_chromiumSettings.GetPath(), _chromiumSettings.GetHeadless()))
                    foreach (var item in listMailAddress)
                    {
                        if (MailRuDomains.Contains(item.Value.Host))
                        {
                            using (var page = await browser.NewPageAsync())
                            {
                                await page.GoToAsync(MailRuRegistration.RegistrationUrl);

                                var emailAlreadyRegistered = await MailRuRegistration.EmailAlreadyRegistered(item.Value.User, item.Value.Host, page);

                                if (emailAlreadyRegistered)
                                {
                                    Info($"{item.Value.Address} - успешная проверка регистрацией - адрес существует");
                                }
                                else
                                {
                                    Info($"{item.Value.Address} - ошибка - проверка регистрацией - адрес не существует");
                                    result.Remove(item.Value.Address);
                                }
                            }
                        }
                        if (item.Value.Host.Equals(ServiceDomains.GetDomain(ServiceCode.Yandex)))
                        {
                            using (var page = await browser.NewPageAsync())
                            {
                                await page.GoToAsync(YandexRegistration.RegistrationUrl);

                                var emailAlreadyRegistered = await YandexRegistration.EmailAlreadyRegistered(item.Value.User, page);

                                if (emailAlreadyRegistered)
                                {
                                    Info($"{item.Value.Address} - успешная проверка регистрацией - адрес существует");
                                }
                                else
                                {
                                    Info($"{item.Value.Address} - ошибка - проверка регистрацией - адрес не существует");
                                    result.Remove(item.Value.Address);
                                }
                            }
                        }
                        if (item.Value.Host.Equals(ServiceDomains.GetDomain(ServiceCode.Gmail)))
                        {
                            using (var page = await browser.NewPageAsync())
                            {
                                await page.GoToAsync(GmailRegistration.RegistrationUrl);

                                var emailAlreadyRegistered = await GmailRegistration.EmailAlreadyRegistered(item.Value.User, page, _chromiumSettings.GetPath());

                                if (emailAlreadyRegistered)
                                {
                                    Info($"{item.Value.Address} - успешная проверка регистрацией - адрес существует");
                                }
                                else
                                {
                                    Info($"{item.Value.Address} - ошибка - проверка регистрацией - адрес не существует");
                                    result.Remove(item.Value.Address);
                                }
                            }
                        }
                    }
            }
            catch (Exception exception)
            {
                Error(exception.ToString());
            }
            return(result);
        }
Beispiel #3
0
        private async Task FillEmail(Page page)
        {
            if (string.IsNullOrEmpty(_data.AccountName))
            {
                _data.AccountName = $"{_data.Firstname.ToLower()}.{_data.Lastname.ToLower()}";
            }

            //await page.TypeAsync("span.b-email__name>input[type='email']", _data.AccountName);
            var defaultDomain = ServiceDomains.GetDomain(ServiceCode.MailRu);

            if (string.IsNullOrEmpty(_data.Domain))
            {
                _data.Domain = ServiceDomains.GetDomain(ServiceCode.MailRu);
            }

            if (page.Url.Contains("light."))
            {
                if (!_data.Domain.ToLower().Equals(defaultDomain))
                {
                    //select domain
                    await page.ClickAsync("select[name='RegistrationDomain'");

                    await page.SelectAsync("select[name='RegistrationDomain'", $"{_data.Domain.ToLower()}");
                }

                await page.ClickAsync("div#loginField input");

                await page.TypeAsync("div#loginField input", _data.AccountName, _typeOptions);

                return;
            }

            if (!_data.Domain.ToLower().Equals(defaultDomain))
            {
                //select domain
                await page.ClickAsync("span.b-email__domain span");

                await page.ClickAsync($"a[data-text='@{_data.Domain}']");
            }

            const string selAltMail = "div.b-tooltip_animate";
            //await page.WaitForTimeoutAsync(1000);
            //var altMailExists = await page.QuerySelectorAsync(selAltMail);
            var emailAlreadyRegistered = await EmailAlreadyRegistered(_data.AccountName, _data.Domain, page);

            //if (altMailExists != null)
            if (emailAlreadyRegistered)
            {
                var selAltMailList = $"{selAltMail} div.b-list__item__content";
                var eAltMailList   = await page.QuerySelectorAsync(selAltMailList);

                if (eAltMailList == null)
                {
                    selAltMailList = "[data-test-id=account-name-tooltip] a";
                    eAltMailList   = await page.QuerySelectorAsync(selAltMailList);
                }
                var altMailElements = await page.QuerySelectorAllAsync(selAltMailList);

                var jsAltMailList = $@"Array.from(document.querySelectorAll('{selAltMailList}')).map(a => a.innerText);";
                var altMailList   = await page.EvaluateExpressionAsync <string[]>(jsAltMailList);

                var altEmail = altMailList.FirstOrDefault(z => z.Contains(_data.Domain));
                if (string.IsNullOrEmpty(altEmail))
                {
                    altEmail = altMailList[0];
                }
                _data.AccountName = altEmail.Split('@')[0];
                _data.Domain      = altEmail.Split('@')[1];
                var idx = Array.IndexOf(altMailList, altEmail);
                //altMailElements = await page.QuerySelectorAllAsync(selAltMailList);
                if (altMailElements.Length > idx)
                {
                    await altMailElements[idx].ClickAsync();
                }
            }
        }
Beispiel #4
0
 private Bot(IAccountData data, ISmsService smsService)
 {
     _data        = data;
     _data.Domain = ServiceDomains.GetDomain(GetServiceCode());
     _smsService  = smsService;
 }