/// <summary> /// Конструктор. /// </summary> /// <param name="options"> Параметры. </param> public MailService(MailingOptions options) { Options = options ?? throw new ArgumentNullException(nameof(options), "Не переданы параметры отправки сообщений"); MailTransport = SmtpClientFactory.Create(options); _disposed = false; }
/// <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(); }
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))); }