public static EmailServicesBuilder AddFluentEmail(this IServiceCollection services, string defaultFromEmail, string defaultFromName = "")
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            var builder = new EmailServicesBuilder(services);

            services.TryAdd(ServiceDescriptor.Transient <IEmail>(x =>
                                                                 new Email(x.GetService <ITemplateRenderer>(), x.GetService <ISender>(), defaultFromEmail, defaultFromName)
                                                                 ));
            services.TryAddTransient <IEmailFactory, EmailFactory>();
            return(builder);
        }
示例#2
0
 public static EmailServicesBuilder AddRazorRenderer(this EmailServicesBuilder builder)
 {
     builder.Services.TryAdd(ServiceDescriptor.Singleton <ITemplateRenderer, RazorRenderer>());
     return(builder);
 }
示例#3
0
 public static EmailServicesBuilder AddSmtpSender(this EmailServicesBuilder builder, string host, int port) => AddSmtpSender(builder, new SmtpClient(host, port));
示例#4
0
 public static EmailServicesBuilder AddSmtpSender(this EmailServicesBuilder builder, Func <SmtpClient> clientFactory)
 {
     builder.Services.TryAdd(ServiceDescriptor.Scoped <ISender>(x => new SmtpSender(clientFactory)));
     return(builder);
 }
示例#5
0
 public static EmailServicesBuilder AddSmtpSender(this EmailServicesBuilder builder, SmtpClient smtpClient)
 {
     builder.Services.TryAdd(ServiceDescriptor.Scoped <ISender>(x => new SmtpSender(smtpClient)));
     return(builder);
 }