BitrixAQA.General.Pop.GetYandexTextFirstMsg C# (CSharp) Method

GetYandexTextFirstMsg() public static method

Получаем текст из первого письма.
public static GetYandexTextFirstMsg ( string userEmail, string Password, string hostname = "pop.yandex.ru", int port = 995, bool useSsl = true ) : string
userEmail string email на который стучимся
Password string пароль
hostname string Сервер
port int Порт
useSsl bool Использовать SSL
return string
        public static string GetYandexTextFirstMsg(string userEmail, string Password, string hostname = "pop.yandex.ru", int port = 995, bool useSsl = true)
        {
            if (userEmail.Contains("@"))
                userEmail = userEmail.Substring(0, userEmail.IndexOf("@"));

            string text = "";
            try
            {
                using (

                    Pop3Client client = new Pop3Client())
                {
                    client.Connect(hostname, port, useSsl);
                    client.Authenticate(userEmail, Password);
                    int messageCount = client.GetMessageCount();
                    Message msg = client.GetMessage(1);
                    if (messageCount != 0)
                    {
                        //если письмо типа текст
                        MessagePart plainText = msg.FindFirstPlainTextVersion();
                        if (plainText != null)
                        {
                            text = plainText.GetBodyAsText();
                        }
                    }
                    return text;
                }
            }
            catch (Exception ex)
            {
                Log.MesQuestion("Скорее всего превышено количество запросов");
                Log.MesQuestion(ex.Message);
                return "_";
            }
        }