/// <summary>
        /// Add the MailClient to the service provider for dependency injection.
        /// Configure the MailClient with the specified options.
        /// </summary>
        /// <param name="services"></param>
        /// <param name="setupAction"></param>
        /// <returns></returns>
        public static IServiceCollection AddMailClient(this IServiceCollection services, Action <MailOptions> setupAction)
        {
            var options = new MailOptions();

            setupAction?.Invoke(options);
            return(services.AddSingleton <MailClient>());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new instance of a MailClient object, and initializes it with the specified options.
        /// </summary>
        /// <param name="options"></param>
        public MailClient(MailOptions options)
        {
            _options = options;

            _client = new SmtpClient(_options.SmtpDNS)
            {
                Port = _options.SmtpPort,
                UseDefaultCredentials = _options.UseDefaultCredentials,
                Credentials           = new System.Net.NetworkCredential(_options.AccountAddress, _options.AccountPassword),
                EnableSsl             = _options.EnableSsl,
                Timeout = _options.Timeout
            };
        }