forked from lukencode/FluentEmail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFluentEmailSmtpBuilderExtensions.cs
29 lines (25 loc) · 1.35 KB
/
FluentEmailSmtpBuilderExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using FluentEmail.Core.Interfaces;
using FluentEmail.Smtp;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System;
using System.Net;
using System.Net.Mail;
namespace Microsoft.Extensions.DependencyInjection
{
public static class FluentEmailSmtpBuilderExtensions
{
public static FluentEmailServicesBuilder AddSmtpSender(this FluentEmailServicesBuilder builder, SmtpClient smtpClient)
{
builder.Services.TryAdd(ServiceDescriptor.Singleton<ISender>(_ => new SmtpSender(smtpClient)));
return builder;
}
public static FluentEmailServicesBuilder AddSmtpSender(this FluentEmailServicesBuilder builder, string host, int port) => AddSmtpSender(builder, () => new SmtpClient(host, port));
public static FluentEmailServicesBuilder AddSmtpSender(this FluentEmailServicesBuilder builder, string host, int port, string username, string password) => AddSmtpSender(builder,
() => new SmtpClient(host, port) { EnableSsl = true, Credentials = new NetworkCredential (username, password) });
public static FluentEmailServicesBuilder AddSmtpSender(this FluentEmailServicesBuilder builder, Func<SmtpClient> clientFactory)
{
builder.Services.TryAdd(ServiceDescriptor.Scoped<ISender>(_ => new SmtpSender(clientFactory)));
return builder;
}
}
}