예제 #1
0
        public bool Equals(MailProtocol mailProtocol)
        {
            if (mailProtocol == null)
            {
                return(false);
            }

            if (ReferenceEquals(this, mailProtocol))
            {
                return(true);
            }

            return(Server == mailProtocol.Server &&
                   Port == mailProtocol.Port &&
                   UseSsl == mailProtocol.UseSsl);
        }
예제 #2
0
        public EmailAccount(string address, string password,
                            int smtpPort = MailProtocol.DEFAULT_SMTP_PORT,
                            int imapPort = MailProtocol.DEFAULT_IMAP_PORT)
        {
            MailAddress mailAddress;

            try
            {
                Regex regex =
                    new Regex(
                        @"[A-Za-z0-9._%+-]+@[A-Za-z0-9._%+-]+\.[A-Za-z]{2,4}");
                if (!regex.IsMatch(address))
                {
                    throw new Exception();
                }

                mailAddress = new MailAddress(address);
            }
            catch
            {
                throw new Exception(
                          "Адрес электронной почты имеет неверный формат.\n" +
                          "Пример адреса: [email protected].");
            }

            Address   = address;
            _password = password ??
                        throw new ArgumentNullException(nameof(password));

            Smtp = new MailProtocol(MailProtocol.MailProtocols.SMTP, mailAddress.Host,
                                    smtpPort);

            Imap = new MailProtocol(MailProtocol.MailProtocols.IMAP, mailAddress.Host,
                                    imapPort);

            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();

            RsaPrivateKey = rsa.ToXmlString(true);
            RsaPublicKey  = rsa.ToXmlString(false);
        }