コード例 #1
0
        /// <summary>
        ///     Конструктор.
        /// </summary>
        /// <param name="options"> Параметры. </param>
        public MailService(MailingOptions options)
        {
            Options = options ?? throw new ArgumentNullException(nameof(options),
                                                                 "Не переданы параметры отправки сообщений");

            MailTransport = SmtpClientFactory.Create(options);
            _disposed     = false;
        }
コード例 #2
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();
 }
コード例 #3
0
        public Task SendAsync(IdentityMessage identityMessage)
        {
            Message messageObject = new Message
            {
                Body    = identityMessage.Body,
                To      = identityMessage.Destination,
                Subject = identityMessage.Subject
            };
            var message = EmailSender.GetMailMessage(messageObject);
            var client  = SmtpClientFactory.Create();

            return(Task.Run(() => client.Send(message)));
        }