Пример #1
0
        /// <param name="client">The <see cref="IMailClient"/> instance.</param>
        /// <param name="host">The server host.</param>
        /// <param name="port">The server port.</param>
        /// <param name="useSsl">Indicates whether to use ssl.</param>
        /// <inheritdoc cref="IMailClient.AuthenticateAsync(Uri, string, string, Encoding, CancellationToken)"/>
        public static Task AuthenticateAsync(this IMailClient client, string host, int port, bool useSsl, string userName, string password, Encoding?encoding = null, CancellationToken cancellationToken = default)
        {
            _ = client ?? throw new ArgumentNullException(nameof(client));
            _ = host ?? throw new ArgumentNullException(nameof(host));
            _ = userName ?? throw new ArgumentNullException(nameof(userName));
            _ = password ?? throw new ArgumentNullException(nameof(password));

            Uri uri = new UriBuilder(useSsl ? $"{client.Protocol}s" : client.Protocol, host, port).Uri;

            return(client.AuthenticateAsync(uri, userName, password, encoding, cancellationToken));
        }
Пример #2
0
        /*
         * Authenticates the client, if we're supposed to authenticate.
         */
        public static async Task Authenticate(Node input, IMailClient client, ConnectionSettings server)
        {
            var username = input.Children
                           .FirstOrDefault(x => x.Name == "server")?
                           .Children.FirstOrDefault(x => x.Name == "username")?
                           .GetEx <string>() ?? server.Username;
            var password = input.Children
                           .FirstOrDefault(x => x.Name == "server")?
                           .Children.FirstOrDefault(x => x.Name == "password")?
                           .GetEx <string>() ?? server.Password;

            if (username != null || password != null)
            {
                await client.AuthenticateAsync(username, password);
            }
        }