コード例 #1
0
 /// <summary>
 /// Добавить FluentEmail.
 /// </summary>
 /// <param name="serviceCollection">Коллекция сервисов.</param>
 /// <param name="settings">Настройки SMTP клиента.</param>
 public static void AddFluentEmail(this IServiceCollection serviceCollection, SmtpClientSettings settings)
 {
     serviceCollection
     .AddScoped <ISender>(serviceProvider => new SmtpSender(SmtpClientFactory.Create(settings)))
     .AddScoped <IEmailNotifier, EmailNotifier>()
     .AddFluentEmail(settings.DefaultEmail)
     .AddRazorRenderer();
 }
コード例 #2
0
        public SmtpClientSettings GetSmtpSettings()
        {
            var settings = new SmtpClientSettings
            {
                Host      = GetValue("Smtp.Host", "smtp.yandex.ru"),
                Port      = Convert.ToInt32(GetValue("Smtp.Port", "587")),
                EnableSsl = Convert.ToBoolean(GetValue("Smtp.EnableSsl", "True")),
                Password  = GetValue("Smtp.Password", "Kludgekludge1"),
                UserName  = GetValue("Smtp.UserName", "*****@*****.**")
            };

            return(settings);
        }
コード例 #3
0
        /// <summary>
        /// Создать Smtp клиент.
        /// </summary>
        /// <param name="settings">Настройки клиента SMTP.</param>
        /// <returns><see cref="SmtpClient"/>.</returns>
        public static SmtpClient Create(SmtpClientSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            return(new SmtpClient
            {
                Host = settings.Host,
                Port = settings.Port,
                Credentials = new NetworkCredential(settings.UserName, settings.Password),
                EnableSsl = settings.EnableSsl,
                DeliveryMethod = SmtpDeliveryMethod.Network
            });
        }
コード例 #4
0
        public void Constructor_ShouldParseConnectionStringAsExpected_WhenConnectionStringIsValid()
        {
            // Arrange
            string input = "Host=ftp.testing.com;Port=20;Username=ABC;Password=123456;";

            // Act
            var settings = new SmtpClientSettings(input);

            // Assert
            settings.Host.ShouldNotBeNull();
            settings.Host.ShouldBe("ftp.testing.com");
            settings.Port.ShouldNotBeNull();
            settings.Port.ShouldBe("20");
            settings.Username.ShouldNotBeNull();
            settings.Username.ShouldBe("ABC");
            settings.Password.ShouldNotBeNull();
            settings.Password.ShouldBe("123456");
        }
コード例 #5
0
        public static async Task SendEmail(IDBContext eddsdbContext, String emailTo, String emailSubject, String emailBody, SmtpClientSettings smtpSettings)
        {
            smtpSettings.GetSettings();

            if (String.IsNullOrWhiteSpace(smtpSettings.EncryptedSmtpPassword)) //Only unencrypted SMTP Passwords are supported
            {
                EmailService emailService = new EmailService(smtpSettings.SmtpServer, smtpSettings.SmtpUsername, smtpSettings.SmtpPassword, smtpSettings.SmtpPort);
                Email        email        = new Email(smtpSettings.EmailFrom, emailTo, emailSubject, emailBody);
                await Task.Run(() => email.Send(emailService));
            }
        }
コード例 #6
0
 public Mailer(SmtpClientSettings smtpClientSettings, ILogger logger)
 {
     _smtpClientSettings = smtpClientSettings;
     _logger             = logger;
 }
コード例 #7
0
 public AuthMessageService(IOptions <SmtpClientSettings> smtpClientSettingsOptions,
                           ILogger <AuthMessageService> logger)
 {
     _logger   = logger;
     _settings = smtpClientSettingsOptions.Value;
 }