1010// --------------------------------------------------------------------------------------------------------------------
1111
1212using System . Collections . Generic ;
13+ using System . Linq ;
1314using System . Runtime . CompilerServices ;
15+ using Devlord . Utilities . Exceptions ;
1416using Microsoft . Extensions . Options ;
1517
1618[ assembly: InternalsVisibleTo ( "Devlord.Utilities.Tests" ) ]
@@ -33,30 +35,32 @@ public MailbotFactory(IOptionsMonitor<DevlordOptions> options)
3335 /// <summary>
3436 /// Gets the instance.
3537 /// </summary>
36- public Mailbot GetMailbot ( string smtpServer )
38+ public Mailbot GetMailbot ( string name )
3739 {
38- smtpServer = smtpServer . ToLower ( ) ;
3940 lock ( DictionaryLock )
4041 {
41- if ( Instances . ContainsKey ( smtpServer ) )
42+ if ( Instances . ContainsKey ( name ) )
4243 {
43- return Instances [ smtpServer ] ;
44+ return Instances [ name ] ;
4445 }
4546
47+ var thisOptions = _options . MailSettings . FirstOrDefault ( n => n . Name == name ) ;
48+
49+ if ( thisOptions == null )
50+ {
51+ throw new DevlordConfigurationException ( $ "Missing mail options for name { name } ") ;
52+ }
53+
4654 var instance = new Mailbot
4755 {
48- SmtpServer = smtpServer ,
49- SmtpPort = _options . SmtpPort ,
50- SmtpLogin = _options . SmtpLogin ,
51- EncryptedPassword = _options . SmtpPassword
56+ SmtpServer = thisOptions . SmtpServer ,
57+ SmtpPort = thisOptions . SmtpPort ,
58+ SmtpLogin = thisOptions . SmtpLogin ,
59+ EncryptedPassword = thisOptions . SmtpPassword ,
60+ Throttles = new Throttles ( thisOptions . MaxPerMinute , thisOptions . MaxPerHour , thisOptions . MaxPerDay )
5261 } ;
53- if ( smtpServer == "smtp.gmail.com" )
54- {
55- instance . Throttles = new GmailThrottles ( ) ;
56- }
5762
58- instance . SmtpServer = smtpServer ;
59- Instances . Add ( smtpServer , instance ) ;
63+ Instances . Add ( name , instance ) ;
6064 return instance ;
6165 }
6266 }
0 commit comments