1- using System ;
1+ using System ;
22using System . Collections . Generic ;
33using System . Linq ;
44using System . Threading . Tasks ;
77using Microsoft . Extensions . Configuration ;
88using Microsoft . Extensions . DependencyInjection ;
99using Microsoft . Extensions . Logging ;
10+ using NETCore . MailKit . Extensions ;
11+ using NETCore . MailKit . Infrastructure . Internal ;
1012
1113namespace NETCore . MailKit . Web
1214{
@@ -19,6 +21,13 @@ public Startup(IHostingEnvironment env)
1921 . AddJsonFile ( "appsettings.json" , optional : false , reloadOnChange : true )
2022 . AddJsonFile ( $ "appsettings.{ env . EnvironmentName } .json", optional : true )
2123 . AddEnvironmentVariables ( ) ;
24+
25+ //add sercets.json https://docs.microsoft.com/en-us/aspnet/core/security/app-secrets
26+ if ( env . IsDevelopment ( ) )
27+ {
28+ builder . AddUserSecrets < Startup > ( ) ;
29+ }
30+
2231 Configuration = builder . Build ( ) ;
2332 }
2433
@@ -29,6 +38,22 @@ public void ConfigureServices(IServiceCollection services)
2938 {
3039 // Add framework services.
3140 services . AddMvc ( ) ;
41+
42+ //Add MailKit
43+ services . AddMailKit ( optionBuilder =>
44+ {
45+
46+ optionBuilder . UseMailKit ( new MailKitOptions ( )
47+ {
48+ //get options from sercets.json
49+ Server = Configuration [ "Server" ] ,
50+ Port = Convert . ToInt32 ( Configuration [ "Port" ] ) ,
51+ SenderName = Configuration [ "SenderName" ] ,
52+ SenderEmail = Configuration [ "SenderEmail" ] ,
53+ Account = Configuration [ "Account" ] ,
54+ Passord = Configuration [ "Passord" ]
55+ } ) ;
56+ } ) ;
3257 }
3358
3459 // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
0 commit comments