8
8
using Microsoft . AspNetCore . StaticFiles ;
9
9
using Signum . Entities . Basics ;
10
10
using Signum . Entities . Files ;
11
+ using Signum . Engine . Mailing . Senders ;
12
+ using Signum . Utilities ;
11
13
12
14
namespace Signum . Engine . Mailing ;
13
15
@@ -23,7 +25,15 @@ public static EmailConfigurationEmbedded Configuration
23
25
get { return getConfiguration ( ) ; }
24
26
}
25
27
26
- public static IEmailSenderManager SenderManager = null ! ;
28
+ static Func < EmailTemplateEntity ? , Lite < Entity > ? , EmailMessageEntity ? , EmailSenderConfigurationEntity > getEmailSenderConfiguration = null ! ;
29
+
30
+ public static Polymorphic < Func < EmailSenderServiceConfigurationEntity , EmailSenderConfigurationEntity , BaseEmailSender > > EmailSenders = new ( ) ;
31
+ public static BaseEmailSender GetEmailSender ( EmailMessageEntity email )
32
+ {
33
+ var template = email . Template ? . Try ( t => EmailTemplateLogic . EmailTemplatesLazy . Value . GetOrThrow ( t ) ) ;
34
+ var config = getEmailSenderConfiguration ( template , email . Target , email ) ;
35
+ return EmailSenders . Invoke ( config . Service , config ) ;
36
+ }
27
37
28
38
internal static void AssertStarted ( SchemaBuilder sb )
29
39
{
@@ -59,12 +69,17 @@ public static void Start(
59
69
e . Sent ,
60
70
e . Target ,
61
71
e . Package ,
72
+ e . SentBy ,
62
73
e . Exception ,
63
74
} ) ;
64
75
65
76
PermissionAuthLogic . RegisterPermissions ( AsyncEmailSenderPermission . ViewAsyncEmailSenderPanel ) ;
66
77
67
- SenderManager = new EmailSenderManager ( getEmailSenderConfiguration ) ;
78
+ EmailLogic . getEmailSenderConfiguration = getEmailSenderConfiguration ;
79
+
80
+ EmailSenders . Register ( ( SmtpEntity s , EmailSenderConfigurationEntity c ) => new SmtpSender ( c , s ) ) ;
81
+ EmailSenders . Register ( ( MicrosoftGraphEntity s , EmailSenderConfigurationEntity c ) => new MicrosoftGraphSender ( c , s ) ) ;
82
+ EmailSenders . Register ( ( ExchangeWebServiceEntity s , EmailSenderConfigurationEntity c ) => new ExchangeWebServiceSender ( c , s ) ) ;
68
83
69
84
EmailGraph . Register ( ) ;
70
85
@@ -133,18 +148,19 @@ public static EmailMessageEntity WithAttachment(this EmailMessageEntity email, F
133
148
public static void SendMail ( this IEmailModel model )
134
149
{
135
150
foreach ( var email in model . CreateEmailMessage ( ) )
136
- SenderManager . Send ( email ) ;
151
+ GetEmailSender ( email ) . Send ( email ) ;
137
152
}
138
153
139
154
public static void SendMail ( this Lite < EmailTemplateEntity > template , ModifiableEntity entity )
140
155
{
141
156
foreach ( var email in template . CreateEmailMessage ( entity ) )
142
- SenderManager . Send ( email ) ;
157
+ GetEmailSender ( email ) . Send ( email ) ;
143
158
}
144
159
145
160
public static void SendMail ( this EmailMessageEntity email )
146
161
{
147
- SenderManager . Send ( email ) ;
162
+ var template = email . Template ? . Try ( t => EmailTemplateLogic . EmailTemplatesLazy . Value . GetOrThrow ( t ) ) ;
163
+ GetEmailSender ( email ) . Send ( email ) ;
148
164
}
149
165
150
166
public static void SendMailAsync ( this IEmailModel model )
@@ -278,7 +294,7 @@ public static void Register()
278
294
CanBeModified = true ,
279
295
FromStates = { EmailMessageState . Created , EmailMessageState . Draft , EmailMessageState . ReadyToSend , EmailMessageState . Outdated } ,
280
296
ToStates = { EmailMessageState . Sent } ,
281
- Execute = ( m , _ ) => EmailLogic . SenderManager . Send ( m )
297
+ Execute = ( m , _ ) => EmailLogic . GetEmailSender ( m ) . Send ( m )
282
298
} . Register ( ) ;
283
299
284
300
@@ -312,12 +328,6 @@ public static void Register()
312
328
}
313
329
}
314
330
315
- public interface IEmailSenderManager
316
- {
317
- void Send ( EmailMessageEntity email ) ;
318
- }
319
-
320
-
321
331
public static class MimeMapping
322
332
{
323
333
public static string GetMimeType ( string fileName )
0 commit comments