public TestCertificateValidatingMailService(MailServiceOptions options, ILogger <CertificateValidatingMailService> logger, MailServerCertificateValidationOptions certificateOptions, IMailTransportFactory mailClientFactory) : base(options, logger, certificateOptions, mailClientFactory) { }
/// <summary>Constructor.</summary> /// <exception cref="ArgumentNullException"> /// Thrown when one or more required arguments are /// null. /// </exception> /// <param name="options"> Options for controlling the operation. </param> /// <param name="root"> The root. </param> /// <param name="templateKeyExpander"> The template key expander. </param> public CultureAwareRazorProject(MailServiceOptions options, string root, Func <CultureInfo, string, string> templateKeyExpander) : base(root) { _options = options ?? throw new ArgumentNullException(nameof(options)); _root = root; _templateKeyExpander = templateKeyExpander ?? throw new ArgumentNullException(nameof(templateKeyExpander)); }
public static void AddMailService(this IServiceCollection services, Action <MailServiceOptions> options) { MailServiceOptions opt = new MailServiceOptions(); options.Invoke(opt); services.AddSingleton <IEmailSender>(new TLSMailSend(opt)); }
/// <summary> Constructor. </summary> /// <exception cref="ArgumentNullException"> Thrown when one or more required arguments are /// null. </exception> /// <param name="options"> Options for controlling the operation. </param> /// <param name="root"> The root. </param> /// <param name="expanders"> The expanders. </param> /// <param name="loggerFactory"> The logger factory. </param> public LocationExpandingRazorProject(MailServiceOptions options, string root, IEnumerable <ILocationExpander> expanders, ILoggerFactory loggerFactory) : base(root) { _options = options ?? throw new ArgumentNullException(nameof(options)); _root = root; _expanders = expanders ?? throw new ArgumentNullException(nameof(expanders)); _logger = loggerFactory.CreateLogger <LocationExpandingRazorProject>(); }
public MailServiceOptions Convert(MailServiceJsonConfiguration jsonOptions) { _jsonOptions = jsonOptions; _options = new MailServiceOptions(); LoadSenderOptions(); LoadFillerOptions(); LoadTemplateOptions(); return(_options); }
private static void ValidateOptions(MailServiceOptions options) { var validationResult = new MailServiceOptionsValidator().Validate(options); if (!validationResult.IsValid) { throw new ValidationException(validationResult, typeof(MailServiceOptions), "Invalid settings."); } }
public void ValidatesEmptyFromName() { var options = new MailServiceOptions(); var validator = new MailServiceOptionsValidator(); var result = validator.Validate(options); var validated = result.Errors.Any(e => e.PropertyName == nameof(MailServiceOptions.FromName) && e.ResourceName == NotEmptyValidator); Assert.IsTrue(validated); }
/// <summary>Initializes a new instance of the <see cref="CertificateValidatingMailService" /> class.</summary> /// <param name="options">The options.</param> /// <param name="logger">The logger to use.</param> /// <param name="certificateOptions">The certificateOptions.</param> /// <param name="mailClientFactory">The mailClientFactory.</param> /// <exception cref="ArgumentNullException">certificateOptions, options</exception> public CertificateValidatingMailService(MailServiceOptions options, ILogger <CertificateValidatingMailService> logger, MailServerCertificateValidationOptions certificateOptions, IMailTransportFactory mailClientFactory) : base(options, logger) { MailClientFactory = mailClientFactory ?? throw new ArgumentNullException(nameof(mailClientFactory)); _certificateOptions = certificateOptions ?? throw new ArgumentNullException(nameof(certificateOptions)); CertificateValidationCallback = ValidateCertificate; }
public void ValidatesEmptyPasswordOnAuthenticate() { var options = new MailServiceOptions { Authenticate = true }; var validator = new MailServiceOptionsValidator(); var result = validator.Validate(options); var validated = result.Errors.Any(e => e.PropertyName == nameof(MailServiceOptions.Password) && e.ResourceName == NotEmptyValidator); Assert.IsTrue(validated); }
public void ValidatesSmtpPort() { var options = new MailServiceOptions { SmtpPort = 0 }; var validator = new MailServiceOptionsValidator(); var result = validator.Validate(options); var validated = result.Errors.Any(e => e.PropertyName == nameof(MailServiceOptions.SmtpPort) && e.ResourceName == GreaterThanValidator); Assert.IsTrue(validated); }
/// <summary>An IServiceCollection extension method that adds a razor light localized.</summary> /// <param name="services"> The services. </param> /// <param name="environment"> The environment. </param> /// <param name="root"> The root. </param> /// <param name="options"> Options for controlling the operation. </param> /// <param name="templateKeyExpander"> The template key expander. </param> private static void AddRazorLightLocalized(this IServiceCollection services, IHostingEnvironment environment, string root, MailServiceOptions options, Func <CultureInfo, string, string> templateKeyExpander) { var absoluteRoot = Path.Combine(environment.ContentRootPath, root); var project = new CultureAwareRazorProject(options, absoluteRoot, templateKeyExpander); var engine = new RazorLightEngineBuilder() .UseProject(project) .UseCachingProvider(new MemoryCachingProvider()) .Build(); services.AddSingleton <IRazorLightEngine>(engine); }
/// <summary>An IServiceCollection extension method that configure mail service templated.</summary> /// <param name="services"> The services. </param> /// <param name="environment"> The environment. </param> /// <param name="configuration"> The configuration. </param> /// <param name="configure"> (Optional) The configure. </param> /// <returns>An IServiceCollection.</returns> public static IServiceCollection ConfigureMailServiceTemplated(this IServiceCollection services, IHostingEnvironment environment, IConfigurationRoot configuration, Action <MailServiceOptions> configure = null) { // parse options _options = configuration.GetConfiguration <MailServiceOptions>(); // let user apply changes configure?.Invoke(_options); // register services.AddSingleton(_options); services.AddRazorLightTemplating(environment, _options, _options.TemplateRoot); services.AddScoped <ITemplatingMailService, MailKitRazorLightTemplatingMailService>(); return(services); }
/// <summary>An IServiceCollection extension method that adds a razor light self.</summary> /// <param name="services"> The services. </param> /// <param name="configuration"> The configuration. </param> /// <param name="environment"> The environment. </param> /// <param name="configure"> (Optional) The configure. </param> /// <param name="templateKeyExpander"> The template key expander. </param> /// <returns>An IServiceCollection.</returns> public static IServiceCollection ConfigureMailServiceLocalized(this IServiceCollection services, IConfigurationRoot configuration, IHostingEnvironment environment, Func <CultureInfo, string, string> templateKeyExpander, Action <MailServiceOptions> configure = null) { // parse options _options = configuration.GetConfiguration <MailServiceOptions>(); // let user apply changes configure?.Invoke(_options); // register services.AddSingleton(_options); services.AddRazorLightLocalized(environment, _options.TemplateRoot, _options, templateKeyExpander); services.AddScoped <ITemplatingMailService, MailKitRazorLightTemplatingMailService>(); return(services); }
/// <summary>An IServiceCollection extension method that adds a razor light templating.</summary> /// <param name="services"> The services. </param> /// <param name="environment"> The environment. </param> /// <param name="options"> Options for controlling the operation. </param> /// <param name="root"> The root. </param> private static void AddRazorLightTemplating(this IServiceCollection services, IHostingEnvironment environment, MailServiceOptions options, string root) { var provider = services.BuildServiceProvider(); var loggerFactory = provider.GetRequiredService <ILoggerFactory>(); var absoluteRoot = Path.Combine(environment.ContentRootPath, root); var expanders = new ILocationExpander[] { new DefaultCultureLocationExpander(), new SharedCultureLocationExpander(), new SharedLocationExpander(), new DefaultLocationExpander() }; var project = new LocationExpandingRazorProject(options, absoluteRoot, expanders, loggerFactory); var engine = new RazorLightEngineBuilder() .UseProject(project) .UseCachingProvider(new MemoryCachingProvider()) .Build(); services.AddSingleton <IRazorLightEngine>(engine); }
public void DefaultsToNoSsl() { var options = new MailServiceOptions(); Assert.IsFalse(options.EnableSsl); }
/// <summary>Initializes a new instance of the <see cref="MailKitSmtpMailService" /> class.</summary> /// <param name="options">The options.</param> protected MailKitSmtpMailService(MailServiceOptions options) { _options = options ?? throw new ArgumentNullException(nameof(options)); ValidateOptions(options); }
public void ItExists() { MailServiceOptions options = new MailServiceOptions(); }
public TestLoggingMailService(MailServiceOptions options, ILogger <LoggingMailService> logger, IMailTransport mailClient) : base(options, logger) { _mailClient = mailClient; }
public EmailService(IOptions <MailServiceOptions> optionsAccessor) { message = new MimeMessage(); _options = optionsAccessor.Value; message.From.Add(new MailboxAddress(_options.SmtpMailFromName, _options.SmtpMailFromEmail)); }
public void DefaultsToNoAuthentication() { var options = new MailServiceOptions(); Assert.IsFalse(options.Authenticate); }
/// <summary>Constructor.</summary> /// <exception cref="ArgumentNullException"> /// Thrown when one or more required arguments are /// null. /// </exception> /// <param name="templatingService"> The engine. </param> /// <param name="options"> Options for controlling the operation. </param> protected MailKitTemplatingMailService(ITemplatingService templatingService, MailServiceOptions options) { TempalingService = templatingService ?? throw new ArgumentNullException(nameof(templatingService)); Options = options ?? throw new ArgumentNullException(nameof(options)); }
/// <summary>Initializes a new instance of the <see cref="LoggingMailService" /> class.</summary> /// <param name="options">The options.</param> /// <param name="logger">The logger.</param> protected LoggingMailService(MailServiceOptions options, ILogger <LoggingMailService> logger) : base(options) { Logger = logger; // we accept null here }
public void DefaultsTo10SecondTimeout() { var options = new MailServiceOptions(); Assert.AreEqual(10, options.TimeOut); }
/// <summary> Constructor. </summary> /// <exception cref="ArgumentNullException"> /// Thrown when one or more required arguments are /// null. /// </exception> /// <param name="viewPath"> Full pathname of the view file. </param> /// <param name="options"> Options for controlling the operation. </param> public MailKitRazorLightTemplatingMailService(string viewPath, MailServiceOptions options) : base(new RazorLightTemplatingService(viewPath), options) { }
public void DefaultsToPort25() { var options = new MailServiceOptions(); Assert.AreEqual(25, options.SmtpPort); }
public void DefaultsToSecureSocketNone() { var options = new MailServiceOptions(); Assert.AreEqual(SecureSocketOptions.None, options.SocketOptions); }
public TestMailKitSmtpMailService(MailServiceOptions options, IMailTransport mailClient) : base(options) { _mailClient = mailClient; }
/// <summary> Constructor. </summary> /// <param name="engine"> The engine. </param> /// <param name="options"> Options for controlling the operation. </param> public MailKitRazorLightTemplatingMailService(IRazorLightEngine engine, MailServiceOptions options) : base(new RazorLightTemplatingService(engine), options) { }