From d4928096eeb6cfd40b064049bf21886796d33102 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Fri, 17 Nov 2023 18:00:55 +0300 Subject: [PATCH 01/24] Support both Text & HTML in the same email --- .../Views/Items/EmailTask.Fields.Edit.cshtml | 16 +++++--- .../Workflows/Activities/EmailTask.cs | 9 ++--- .../Drivers/EmailTaskDisplayDriver.cs | 4 +- .../ViewModels/EmailTaskViewModel.cs | 2 +- .../Controllers/ControllerExtensions.cs | 2 +- .../EmailAuthenticatorController.cs | 10 ++--- .../Workflows/Activities/RegisterUserTask.cs | 4 +- .../MailMessage.cs | 40 +++++++------------ .../MailMessageFormat.cs | 8 ++++ .../Services/SmtpService.cs | 19 +++++---- .../Services/EmailNotificationProvider.cs | 4 +- 11 files changed, 62 insertions(+), 56 deletions(-) create mode 100644 src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageFormat.cs diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml index 4a8fa929118..c3ba9d7d603 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml @@ -1,3 +1,4 @@ +@using OrchardCore.Email @using OrchardCore.Email.Workflows.ViewModels @model EmailTaskViewModel @@ -50,12 +51,15 @@ @T["The subject of the email message. With Liquid support."] -
-
- - - @T["If checked, indicates the body of the email message will be sent as HTML."] -
+
+ + + + @T["The Format of the email message."]
diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs index cf7b9d1c8ff..008c72dad6d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs @@ -82,13 +82,12 @@ public WorkflowExpression Body set => SetProperty(value); } - public bool IsHtmlBody + public MailMessageFormat Format { - get => GetProperty(() => true); + get => GetProperty(() => MailMessageFormat.Text); set => SetProperty(value); } - public override IEnumerable GetPossibleOutcomes(WorkflowExecutionContext workflowContext, ActivityContext activityContext) { return Outcomes(S["Done"], S["Failed"]); @@ -103,7 +102,7 @@ public override async Task ExecuteAsync(WorkflowExecuti var cc = await _expressionEvaluator.EvaluateAsync(Cc, workflowContext, null); var bcc = await _expressionEvaluator.EvaluateAsync(Bcc, workflowContext, null); var subject = await _expressionEvaluator.EvaluateAsync(Subject, workflowContext, null); - var body = await _expressionEvaluator.EvaluateAsync(Body, workflowContext, IsHtmlBody ? _htmlEncoder : null); + var body = await _expressionEvaluator.EvaluateAsync(Body, workflowContext, Format == MailMessageFormat.Text ? null : _htmlEncoder); var message = new MailMessage { @@ -116,7 +115,7 @@ public override async Task ExecuteAsync(WorkflowExecuti ReplyTo = replyTo?.Trim(), Subject = subject?.Trim(), Body = body?.Trim(), - IsHtmlBody = IsHtmlBody + Format = Format }; if (!string.IsNullOrWhiteSpace(sender)) diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Drivers/EmailTaskDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Drivers/EmailTaskDisplayDriver.cs index 4a441d7288a..840e1f3d8f2 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Drivers/EmailTaskDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Drivers/EmailTaskDisplayDriver.cs @@ -15,7 +15,7 @@ protected override void EditActivity(EmailTask activity, EmailTaskViewModel mode model.ReplyToExpression = activity.ReplyTo.Expression; model.SubjectExpression = activity.Subject.Expression; model.Body = activity.Body.Expression; - model.IsHtmlBody = activity.IsHtmlBody; + model.Format = activity.Format; model.BccExpression = activity.Bcc.Expression; model.CcExpression = activity.Cc.Expression; } @@ -28,7 +28,7 @@ protected override void UpdateActivity(EmailTaskViewModel model, EmailTask activ activity.ReplyTo = new WorkflowExpression(model.ReplyToExpression); activity.Subject = new WorkflowExpression(model.SubjectExpression); activity.Body = new WorkflowExpression(model.Body); - activity.IsHtmlBody = model.IsHtmlBody; + activity.Format = model.Format; activity.Bcc = new WorkflowExpression(model.BccExpression); activity.Cc = new WorkflowExpression(model.CcExpression); } diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/ViewModels/EmailTaskViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/ViewModels/EmailTaskViewModel.cs index 1b4adf4bb4e..9f735d54225 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/ViewModels/EmailTaskViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/ViewModels/EmailTaskViewModel.cs @@ -18,6 +18,6 @@ public class EmailTaskViewModel public string Body { get; set; } - public bool IsHtmlBody { get; set; } + public MailMessageFormat Format { get; set; } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ControllerExtensions.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ControllerExtensions.cs index 409cc4b90fc..28c0bdccc7e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ControllerExtensions.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ControllerExtensions.cs @@ -40,7 +40,7 @@ internal static async Task SendEmailAsync(this Controller controller, stri To = email, Subject = subject, Body = body, - IsHtmlBody = true + Format = MailMessageFormat.Html }; var result = await smtpService.SendAsync(message); diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/EmailAuthenticatorController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/EmailAuthenticatorController.cs index 7295e12b886..e8590824dce 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/EmailAuthenticatorController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/EmailAuthenticatorController.cs @@ -97,13 +97,13 @@ public async Task RequestCode() var code = await UserManager.GenerateEmailConfirmationTokenAsync(user); - var setings = (await SiteService.GetSiteSettingsAsync()).As(); + var settings = (await SiteService.GetSiteSettingsAsync()).As(); var message = new MailMessage() { To = await UserManager.GetEmailAsync(user), - Subject = await GetSubjectAsync(setings, user, code), - Body = await GetBodyAsync(setings, user, code), - IsHtmlBody = true, + Subject = await GetSubjectAsync(settings, user, code), + Body = await GetBodyAsync(settings, user, code), + Format = MailMessageFormat.Html }; var result = await _smtpService.SendAsync(message); @@ -175,7 +175,7 @@ public async Task SendCode() To = await UserManager.GetEmailAsync(user), Subject = await GetSubjectAsync(settings, user, code), Body = await GetBodyAsync(settings, user, code), - IsHtmlBody = true, + Format = MailMessageFormat.Html }; var result = await _smtpService.SendAsync(message); diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Workflows/Activities/RegisterUserTask.cs b/src/OrchardCore.Modules/OrchardCore.Users/Workflows/Activities/RegisterUserTask.cs index 0400668aeea..c5a3ed22e04 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Workflows/Activities/RegisterUserTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Workflows/Activities/RegisterUserTask.cs @@ -134,12 +134,12 @@ public override async Task ExecuteAsync(WorkflowExecuti var body = await _expressionEvaluator.EvaluateAsync(ConfirmationEmailTemplate, workflowContext, _htmlEncoder); - var message = new MailMessage() + var message = new MailMessage { To = email, Subject = subject, Body = body, - IsHtmlBody = true + Format = MailMessageFormat.Html }; var smtpService = _httpContextAccessor.HttpContext.RequestServices.GetService(); diff --git a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs index 15362688410..0bf16f5bab7 100644 --- a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs +++ b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs @@ -49,46 +49,36 @@ public class MailMessage /// /// Gets or sets the message content aka body. /// - /// This property is work in conjunction with to determine the body type.. + /// This property is work in conjunction with to determine the body type. public string Body { get; set; } + /// + /// Gets or sets the message format. Default is . + /// + public MailMessageFormat Format { get; set; } = MailMessageFormat.Text; + /// /// Gets or sets the message content as plain text. /// - [Obsolete("This property is deprecated, please use Body instead.")] - public string BodyText - { - get => Body; - set - { - Body = value; - IsHtmlBody = false; - } - } + [Obsolete("This property is deprecated, please use Body instead.", true)] + public string BodyText { get; set; } /// /// Gets or sets whether the message body is an HTML. /// - [Obsolete("This property is deprecated, please use IsHtmlBody instead.")] - public bool IsBodyHtml - { - get => IsHtmlBody; - set => IsHtmlBody = value; - } + [Obsolete("This property is deprecated, please use IsHtmlBody instead.", true)] + public bool IsBodyHtml { get; set; } - /// + /// /// Gets or sets whether the message body is plain text. /// - [Obsolete("This property is deprecated, please use IsHtmlBody instead.")] - public bool IsBodyText - { - get => !IsHtmlBody; - set => IsHtmlBody = !value; - } + [Obsolete("This property is deprecated, please use IsHtmlBody instead.", true)] + public bool IsBodyText { get; set; } - /// + /// /// Gets or sets whether the message body is an HTML or not. Default is false which is plain text. /// + [Obsolete("This property is deprecated, please use Format instead.", true)] public bool IsHtmlBody { get; set; } /// diff --git a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageFormat.cs b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageFormat.cs new file mode 100644 index 00000000000..81daadfd670 --- /dev/null +++ b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageFormat.cs @@ -0,0 +1,8 @@ +namespace OrchardCore.Email; + +public enum MailMessageFormat +{ + Text, + Html, + All +} diff --git a/src/OrchardCore/OrchardCore.Email.Core/Services/SmtpService.cs b/src/OrchardCore/OrchardCore.Email.Core/Services/SmtpService.cs index cb18f00e1e3..9ba1d87ed17 100644 --- a/src/OrchardCore/OrchardCore.Email.Core/Services/SmtpService.cs +++ b/src/OrchardCore/OrchardCore.Email.Core/Services/SmtpService.cs @@ -215,14 +215,19 @@ private MimeMessage FromMailMessage(MailMessage message, IList mimeMessage.Subject = message.Subject; var body = new BodyBuilder(); - - if (message.IsHtmlBody) - { - body.HtmlBody = message.Body; - } - else + switch (message.Format) { - body.TextBody = message.Body; + case MailMessageFormat.Html: + body.HtmlBody = message.Body; + break; + case MailMessageFormat.All: + body.TextBody = message.Body; + body.HtmlBody = message.Body; + break; + case MailMessageFormat.Text: + default: + body.TextBody = message.Body; + break; } foreach (var attachment in message.Attachments) diff --git a/src/OrchardCore/OrchardCore.Notifications.Core/Services/EmailNotificationProvider.cs b/src/OrchardCore/OrchardCore.Notifications.Core/Services/EmailNotificationProvider.cs index e28d5a85664..2e138070992 100644 --- a/src/OrchardCore/OrchardCore.Notifications.Core/Services/EmailNotificationProvider.cs +++ b/src/OrchardCore/OrchardCore.Notifications.Core/Services/EmailNotificationProvider.cs @@ -41,12 +41,12 @@ public async Task TrySendAsync(object notify, INotificationMessage message if (message.IsHtmlPreferred && !string.IsNullOrWhiteSpace(message.HtmlBody)) { mailMessage.Body = message.HtmlBody; - mailMessage.IsHtmlBody = true; + mailMessage.Format = MailMessageFormat.Html; } else { mailMessage.Body = message.TextBody; - mailMessage.IsHtmlBody = false; + mailMessage.Format = MailMessageFormat.Text; } var result = await _smtpService.SendAsync(mailMessage); From fefd6ff4b8841024d6e488effc90cdcbf6cec27d Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sat, 25 Nov 2023 19:04:11 +0300 Subject: [PATCH 02/24] Remove extra whitespace --- src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs index 0bf16f5bab7..ce0c186a9ec 100644 --- a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs +++ b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs @@ -69,13 +69,13 @@ public class MailMessage [Obsolete("This property is deprecated, please use IsHtmlBody instead.", true)] public bool IsBodyHtml { get; set; } - /// + /// /// Gets or sets whether the message body is plain text. /// [Obsolete("This property is deprecated, please use IsHtmlBody instead.", true)] public bool IsBodyText { get; set; } - /// + /// /// Gets or sets whether the message body is an HTML or not. Default is false which is plain text. /// [Obsolete("This property is deprecated, please use Format instead.", true)] From 57403f1e199260ee66044ce0e5f5178f37f3f8b4 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sun, 26 Nov 2023 19:20:00 +0300 Subject: [PATCH 03/24] Introduce MainMessageBody --- .../Views/Items/EmailTask.Fields.Edit.cshtml | 66 ++++++++++++++----- .../Workflows/Activities/EmailTask.cs | 18 +++-- .../Drivers/EmailTaskDisplayDriver.cs | 8 +-- .../ViewModels/EmailTaskViewModel.cs | 4 +- .../Controllers/ControllerExtensions.cs | 3 +- .../EmailAuthenticatorController.cs | 6 +- .../Workflows/Activities/RegisterUserTask.cs | 3 +- .../MailMessage.cs | 6 +- .../MailMessageBody.cs | 17 +++++ .../Services/SmtpService.cs | 18 ++--- .../Services/EmailNotificationProvider.cs | 9 +-- .../Workflows/EmailTaskTests.cs | 2 +- 12 files changed, 102 insertions(+), 58 deletions(-) create mode 100644 src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageBody.cs diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml index c3ba9d7d603..6a7181626e5 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml @@ -51,21 +51,27 @@ @T["The subject of the email message. With Liquid support."]
-
- - + + + - + @T["The Format of the email message."]
-
- - - @T["The body of the email message. With Liquid support."] +
+ + + @T["The plain text body of the email message. With Liquid support."] +
+ +
+ + + @T["The HTML body of the email message. With Liquid support."]
@@ -77,12 +83,36 @@ diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs index 008c72dad6d..25c0b36bf69 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs @@ -76,7 +76,13 @@ public WorkflowExpression Subject set => SetProperty(value); } - public WorkflowExpression Body + public WorkflowExpression TextBody + { + get => GetProperty(() => new WorkflowExpression()); + set => SetProperty(value); + } + + public WorkflowExpression HtmlBody { get => GetProperty(() => new WorkflowExpression()); set => SetProperty(value); @@ -102,7 +108,8 @@ public override async Task ExecuteAsync(WorkflowExecuti var cc = await _expressionEvaluator.EvaluateAsync(Cc, workflowContext, null); var bcc = await _expressionEvaluator.EvaluateAsync(Bcc, workflowContext, null); var subject = await _expressionEvaluator.EvaluateAsync(Subject, workflowContext, null); - var body = await _expressionEvaluator.EvaluateAsync(Body, workflowContext, Format == MailMessageFormat.Text ? null : _htmlEncoder); + var textBody = await _expressionEvaluator.EvaluateAsync(TextBody, workflowContext, null); + var htmlBody = await _expressionEvaluator.EvaluateAsync(HtmlBody, workflowContext, _htmlEncoder); var message = new MailMessage { @@ -114,8 +121,11 @@ public override async Task ExecuteAsync(WorkflowExecuti // Email reply-to header https://tools.ietf.org/html/rfc4021#section-2.1.4 ReplyTo = replyTo?.Trim(), Subject = subject?.Trim(), - Body = body?.Trim(), - Format = Format + Content = new MailMessageBody + { + Text = textBody?.Trim(), + Html = htmlBody?.Trim() + } }; if (!string.IsNullOrWhiteSpace(sender)) diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Drivers/EmailTaskDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Drivers/EmailTaskDisplayDriver.cs index 840e1f3d8f2..13f276fa3c5 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Drivers/EmailTaskDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Drivers/EmailTaskDisplayDriver.cs @@ -14,8 +14,8 @@ protected override void EditActivity(EmailTask activity, EmailTaskViewModel mode model.RecipientsExpression = activity.Recipients.Expression; model.ReplyToExpression = activity.ReplyTo.Expression; model.SubjectExpression = activity.Subject.Expression; - model.Body = activity.Body.Expression; - model.Format = activity.Format; + model.TextBody = activity.TextBody.Expression; + model.HtmlBody = activity.HtmlBody.Expression; model.BccExpression = activity.Bcc.Expression; model.CcExpression = activity.Cc.Expression; } @@ -27,8 +27,8 @@ protected override void UpdateActivity(EmailTaskViewModel model, EmailTask activ activity.Recipients = new WorkflowExpression(model.RecipientsExpression); activity.ReplyTo = new WorkflowExpression(model.ReplyToExpression); activity.Subject = new WorkflowExpression(model.SubjectExpression); - activity.Body = new WorkflowExpression(model.Body); - activity.Format = model.Format; + activity.TextBody = new WorkflowExpression(model.TextBody); + activity.HtmlBody = new WorkflowExpression(model.HtmlBody); activity.Bcc = new WorkflowExpression(model.BccExpression); activity.Cc = new WorkflowExpression(model.CcExpression); } diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/ViewModels/EmailTaskViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/ViewModels/EmailTaskViewModel.cs index 9f735d54225..3be032b4854 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/ViewModels/EmailTaskViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/ViewModels/EmailTaskViewModel.cs @@ -16,8 +16,8 @@ public class EmailTaskViewModel public string SubjectExpression { get; set; } - public string Body { get; set; } + public string TextBody { get; set; } - public MailMessageFormat Format { get; set; } + public string HtmlBody { get; set; } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ControllerExtensions.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ControllerExtensions.cs index 28c0bdccc7e..ad675e41406 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ControllerExtensions.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ControllerExtensions.cs @@ -39,8 +39,7 @@ internal static async Task SendEmailAsync(this Controller controller, stri { To = email, Subject = subject, - Body = body, - Format = MailMessageFormat.Html + Content = new MailMessageBody { Html = body } }; var result = await smtpService.SendAsync(message); diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/EmailAuthenticatorController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/EmailAuthenticatorController.cs index e8590824dce..40a24d9927d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/EmailAuthenticatorController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/EmailAuthenticatorController.cs @@ -102,8 +102,7 @@ public async Task RequestCode() { To = await UserManager.GetEmailAsync(user), Subject = await GetSubjectAsync(settings, user, code), - Body = await GetBodyAsync(settings, user, code), - Format = MailMessageFormat.Html + Body = await GetBodyAsync(settings, user, code) }; var result = await _smtpService.SendAsync(message); @@ -174,8 +173,7 @@ public async Task SendCode() { To = await UserManager.GetEmailAsync(user), Subject = await GetSubjectAsync(settings, user, code), - Body = await GetBodyAsync(settings, user, code), - Format = MailMessageFormat.Html + Body = await GetBodyAsync(settings, user, code) }; var result = await _smtpService.SendAsync(message); diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Workflows/Activities/RegisterUserTask.cs b/src/OrchardCore.Modules/OrchardCore.Users/Workflows/Activities/RegisterUserTask.cs index c5a3ed22e04..7cf0d11bdba 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Workflows/Activities/RegisterUserTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Workflows/Activities/RegisterUserTask.cs @@ -138,8 +138,7 @@ public override async Task ExecuteAsync(WorkflowExecuti { To = email, Subject = subject, - Body = body, - Format = MailMessageFormat.Html + Content = new MailMessageBody { Html = body } }; var smtpService = _httpContextAccessor.HttpContext.RequestServices.GetService(); diff --git a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs index ce0c186a9ec..b18f4592a7d 100644 --- a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs +++ b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs @@ -49,9 +49,13 @@ public class MailMessage /// /// Gets or sets the message content aka body. /// - /// This property is work in conjunction with to determine the body type. public string Body { get; set; } + /// + /// Gets or sets the message content aka body. + /// + public MailMessageBody Content { get; set; } + /// /// Gets or sets the message format. Default is . /// diff --git a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageBody.cs b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageBody.cs new file mode 100644 index 00000000000..6553aa4b4ea --- /dev/null +++ b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageBody.cs @@ -0,0 +1,17 @@ +namespace OrchardCore.Email; + +/// +/// Represents a body for . +/// +public class MailMessageBody +{ + /// + /// Gets or sets the body in plain text format. + /// + public string Text { get; set; } + + /// + /// Gets or sets the body in HTML format. + /// + public string Html { get; set; } +} diff --git a/src/OrchardCore/OrchardCore.Email.Core/Services/SmtpService.cs b/src/OrchardCore/OrchardCore.Email.Core/Services/SmtpService.cs index 9ba1d87ed17..b33cbae5dff 100644 --- a/src/OrchardCore/OrchardCore.Email.Core/Services/SmtpService.cs +++ b/src/OrchardCore/OrchardCore.Email.Core/Services/SmtpService.cs @@ -214,21 +214,11 @@ private MimeMessage FromMailMessage(MailMessage message, IList mimeMessage.Subject = message.Subject; - var body = new BodyBuilder(); - switch (message.Format) + var body = new BodyBuilder { - case MailMessageFormat.Html: - body.HtmlBody = message.Body; - break; - case MailMessageFormat.All: - body.TextBody = message.Body; - body.HtmlBody = message.Body; - break; - case MailMessageFormat.Text: - default: - body.TextBody = message.Body; - break; - } + TextBody = message.Content?.Text, + HtmlBody = message.Content?.Html + }; foreach (var attachment in message.Attachments) { diff --git a/src/OrchardCore/OrchardCore.Notifications.Core/Services/EmailNotificationProvider.cs b/src/OrchardCore/OrchardCore.Notifications.Core/Services/EmailNotificationProvider.cs index 2e138070992..de14dcfe5f2 100644 --- a/src/OrchardCore/OrchardCore.Notifications.Core/Services/EmailNotificationProvider.cs +++ b/src/OrchardCore/OrchardCore.Notifications.Core/Services/EmailNotificationProvider.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.Extensions.Localization; using OrchardCore.Email; @@ -36,17 +35,15 @@ public async Task TrySendAsync(object notify, INotificationMessage message { To = user.Email, Subject = message.Summary, + Content = new MailMessageBody() }; - if (message.IsHtmlPreferred && !string.IsNullOrWhiteSpace(message.HtmlBody)) { - mailMessage.Body = message.HtmlBody; - mailMessage.Format = MailMessageFormat.Html; + mailMessage.Content.Html = message.HtmlBody; } else { - mailMessage.Body = message.TextBody; - mailMessage.Format = MailMessageFormat.Text; + mailMessage.Content.Text = message.TextBody; } var result = await _smtpService.SendAsync(mailMessage); diff --git a/test/OrchardCore.Tests/Modules/OrchardCore.Email/Workflows/EmailTaskTests.cs b/test/OrchardCore.Tests/Modules/OrchardCore.Email/Workflows/EmailTaskTests.cs index c5cf27bdfb3..7d436087401 100644 --- a/test/OrchardCore.Tests/Modules/OrchardCore.Email/Workflows/EmailTaskTests.cs +++ b/test/OrchardCore.Tests/Modules/OrchardCore.Email/Workflows/EmailTaskTests.cs @@ -22,7 +22,7 @@ public async Task ExecuteTask_WhenToAndCcAndBccAreNotSet_ShouldFails() HtmlEncoder.Default) { Subject = new WorkflowExpression("Test"), - Body = new WorkflowExpression("Test message!!") + HtmlBody = new WorkflowExpression("Test message!!") }; var executionContext = new WorkflowExecutionContext( From 9d563189e7c3800d8dc92c2a0f6f6af3e13cf850 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sun, 26 Nov 2023 19:41:24 +0300 Subject: [PATCH 04/24] Cleanup --- .../Controllers/AdminController.cs | 3 +-- .../Views/Items/EmailTask.Fields.Edit.cshtml | 19 ++++++++++----- .../Workflows/Activities/EmailTask.cs | 6 ----- .../EmailAuthenticatorController.cs | 5 ++-- .../MailMessage.cs | 8 ++----- .../MailMessageFormat.cs | 8 ------- test/OrchardCore.Tests/Email/EmailTests.cs | 24 +++++++++---------- 7 files changed, 30 insertions(+), 43 deletions(-) delete mode 100644 src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageFormat.cs diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Email/Controllers/AdminController.cs index 6d85301f904..a90ed2a802b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email/Controllers/AdminController.cs @@ -1,4 +1,3 @@ -using System; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -93,7 +92,7 @@ private static MailMessage CreateMessageFromViewModel(SmtpSettingsViewModel test if (!string.IsNullOrWhiteSpace(testSettings.Body)) { - message.Body = testSettings.Body; + message.Content = new MailMessageBody { Text = testSettings.Body }; } return message; diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml index 6a7181626e5..a4b8345589c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml @@ -1,6 +1,14 @@ -@using OrchardCore.Email @using OrchardCore.Email.Workflows.ViewModels @model EmailTaskViewModel +@functions +{ + private enum MailMessageFormat + { + Text, + Html, + All + } +}
@@ -54,12 +62,11 @@
- - @T["The Format of the email message."] + @T["The format of the email message."]
diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs index 25c0b36bf69..0baf114c9d3 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs @@ -88,12 +88,6 @@ public WorkflowExpression HtmlBody set => SetProperty(value); } - public MailMessageFormat Format - { - get => GetProperty(() => MailMessageFormat.Text); - set => SetProperty(value); - } - public override IEnumerable GetPossibleOutcomes(WorkflowExecutionContext workflowContext, ActivityContext activityContext) { return Outcomes(S["Done"], S["Failed"]); diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/EmailAuthenticatorController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/EmailAuthenticatorController.cs index 40a24d9927d..ca90970acdf 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/EmailAuthenticatorController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/EmailAuthenticatorController.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; using System.IO; using System.Text.Encodings.Web; @@ -102,7 +101,7 @@ public async Task RequestCode() { To = await UserManager.GetEmailAsync(user), Subject = await GetSubjectAsync(settings, user, code), - Body = await GetBodyAsync(settings, user, code) + Content = new MailMessageBody { Html = await GetBodyAsync(settings, user, code) } }; var result = await _smtpService.SendAsync(message); @@ -173,7 +172,7 @@ public async Task SendCode() { To = await UserManager.GetEmailAsync(user), Subject = await GetSubjectAsync(settings, user, code), - Body = await GetBodyAsync(settings, user, code) + Content = new MailMessageBody { Html = await GetBodyAsync(settings, user, code) } }; var result = await _smtpService.SendAsync(message); diff --git a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs index b18f4592a7d..7b954705bc5 100644 --- a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs +++ b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs @@ -49,6 +49,7 @@ public class MailMessage /// /// Gets or sets the message content aka body. /// + [Obsolete("This property is deprecated, please use Content instead.", true)] public string Body { get; set; } /// @@ -56,15 +57,10 @@ public class MailMessage /// public MailMessageBody Content { get; set; } - /// - /// Gets or sets the message format. Default is . - /// - public MailMessageFormat Format { get; set; } = MailMessageFormat.Text; - /// /// Gets or sets the message content as plain text. /// - [Obsolete("This property is deprecated, please use Body instead.", true)] + [Obsolete("This property is deprecated, please use Content instead.", true)] public string BodyText { get; set; } /// diff --git a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageFormat.cs b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageFormat.cs deleted file mode 100644 index 81daadfd670..00000000000 --- a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageFormat.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace OrchardCore.Email; - -public enum MailMessageFormat -{ - Text, - Html, - All -} diff --git a/test/OrchardCore.Tests/Email/EmailTests.cs b/test/OrchardCore.Tests/Email/EmailTests.cs index 1440ed8e4b1..a388da002d0 100644 --- a/test/OrchardCore.Tests/Email/EmailTests.cs +++ b/test/OrchardCore.Tests/Email/EmailTests.cs @@ -14,7 +14,7 @@ public async Task SendEmail_WithToHeader() { To = "info@oc.com", Subject = "Test", - Body = "Test Message" + Content = new MailMessageBody { Text = "Test Message" } }; // Act @@ -32,7 +32,7 @@ public async Task SendEmail_WithCcHeader() { Cc = "info@oc.com", Subject = "Test", - Body = "Test Message" + Content = new MailMessageBody { Text = "Test Message" } }; // Act @@ -50,7 +50,7 @@ public async Task SendEmail_WithBccHeader() { Bcc = "info@oc.com", Subject = "Test", - Body = "Test Message" + Content = new MailMessageBody { Text = "Test Message" } }; // Act @@ -67,7 +67,7 @@ public async Task SendEmail_WithDisplayName() { To = "info@oc.com", Subject = "Test", - Body = "Test Message" + Content = new MailMessageBody { Text = "Test Message" } }; await SendEmailAsync(message, "Your Name "); @@ -80,7 +80,7 @@ public async Task SendEmail_UsesDefaultSender() { To = "info@oc.com", Subject = "Test", - Body = "Test Message" + Content = new MailMessageBody { Text = "Test Message" } }; var content = await SendEmailAsync(message, "Your Name "); @@ -94,7 +94,7 @@ public async Task SendEmail_UsesCustomSender() { To = "info@oc.com", Subject = "Test", - Body = "Test Message", + Content = new MailMessageBody { Text = "Test Message" }, From = "My Name ", }; var content = await SendEmailAsync(message, "Your Name "); @@ -110,7 +110,7 @@ public async Task SendEmail_UsesCustomAuthorAndSender() { To = "info@oc.com", Subject = "Test", - Body = "Test Message", + Content = new MailMessageBody { Text = "Test Message" }, Sender = "Hisham Bin Ateya ", }; var content = await SendEmailAsync(message, "Sebastien Ros "); @@ -126,7 +126,7 @@ public async Task SendEmail_UsesMultipleAuthors() { To = "info@oc.com", Subject = "Test", - Body = "Test Message", + Content = new MailMessageBody { Text = "Test Message" }, From = "sebastienros@gmail.com,hishamco_2007@hotmail.com" }; var content = await SendEmailAsync(message, "Hisham Bin Ateya "); @@ -142,7 +142,7 @@ public async Task SendEmail_UsesReplyTo() { To = "Hisham Bin Ateya ", Subject = "Test", - Body = "Test Message", + Content = new MailMessageBody { Text = "Test Message" }, From = "Hisham Bin Ateya ", ReplyTo = "Hisham Bin Ateya ", }; @@ -159,7 +159,7 @@ public async Task ReplyTo_ShouldHaveAuthors_IfNotSet() { To = "info@oc.com", Subject = "Test", - Body = "Test Message", + Content = new MailMessageBody { Text = "Test Message" }, From = "Sebastien Ros " }; var content = await SendEmailAsync(message, "Your Name "); @@ -190,7 +190,7 @@ public async Task SendEmail_WithoutToAndCcAndBccHeaders_ShouldThrowsException() var message = new MailMessage { Subject = "Test", - Body = "Test Message" + Content = new MailMessageBody { Text = "Test Message" } }; var settings = new SmtpSettings { @@ -214,7 +214,7 @@ public async Task SendOfflineEmailHasNoResponse() { To = "info@oc.com", Subject = "Test", - Body = "Test Message" + Content = new MailMessageBody { Text = "Test Message" } }; var settings = new SmtpSettings { From 9f52debb98cff15bae5939ca6de307bbc1ea860e Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sun, 26 Nov 2023 20:23:12 +0300 Subject: [PATCH 05/24] Revert some changes --- .../MailMessage.cs | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs index 7b954705bc5..648504fd346 100644 --- a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs +++ b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs @@ -53,32 +53,48 @@ public class MailMessage public string Body { get; set; } /// - /// Gets or sets the message content aka body. + /// Gets or sets the message content as plain text. /// - public MailMessageBody Content { get; set; } + [Obsolete("This property is deprecated, please use Body instead.", true)] + public string BodyText + { + get => Body; + set + { + Body = value; + IsHtmlBody = false; + } + } /// - /// Gets or sets the message content as plain text. + /// Gets or sets the message content aka body. /// - [Obsolete("This property is deprecated, please use Content instead.", true)] - public string BodyText { get; set; } + public MailMessageBody Content { get; set; } /// /// Gets or sets whether the message body is an HTML. /// [Obsolete("This property is deprecated, please use IsHtmlBody instead.", true)] - public bool IsBodyHtml { get; set; } + public bool IsBodyHtml + { + get => IsHtmlBody; + set => IsHtmlBody = value; + } /// /// Gets or sets whether the message body is plain text. /// [Obsolete("This property is deprecated, please use IsHtmlBody instead.", true)] - public bool IsBodyText { get; set; } + public bool IsBodyText + { + get => !IsHtmlBody; + set => IsHtmlBody = !value; + } /// /// Gets or sets whether the message body is an HTML or not. Default is false which is plain text. /// - [Obsolete("This property is deprecated, please use Format instead.", true)] + [Obsolete("This property is deprecated, please use Content instead.", true)] public bool IsHtmlBody { get; set; } /// From 5843a390eb6d0a96c78c4fa377b36a4d05484af0 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Mon, 27 Nov 2023 15:13:02 +0300 Subject: [PATCH 06/24] Content -> Body --- .../Controllers/AdminController.cs | 2 +- .../Workflows/Activities/EmailTask.cs | 2 +- .../Controllers/ControllerExtensions.cs | 2 +- .../EmailAuthenticatorController.cs | 4 +-- .../Workflows/Activities/RegisterUserTask.cs | 2 +- .../MailMessage.cs | 30 +++---------------- .../Services/SmtpService.cs | 4 +-- .../Services/EmailNotificationProvider.cs | 6 ++-- src/docs/releases/1.8.0.md | 4 +++ test/OrchardCore.Tests/Email/EmailTests.cs | 24 +++++++-------- 10 files changed, 31 insertions(+), 49 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Email/Controllers/AdminController.cs index a90ed2a802b..b39651593ef 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email/Controllers/AdminController.cs @@ -92,7 +92,7 @@ private static MailMessage CreateMessageFromViewModel(SmtpSettingsViewModel test if (!string.IsNullOrWhiteSpace(testSettings.Body)) { - message.Content = new MailMessageBody { Text = testSettings.Body }; + message.Body = new MailMessageBody { Text = testSettings.Body }; } return message; diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs index 0baf114c9d3..206d330cc5d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs @@ -115,7 +115,7 @@ public override async Task ExecuteAsync(WorkflowExecuti // Email reply-to header https://tools.ietf.org/html/rfc4021#section-2.1.4 ReplyTo = replyTo?.Trim(), Subject = subject?.Trim(), - Content = new MailMessageBody + Body = new MailMessageBody { Text = textBody?.Trim(), Html = htmlBody?.Trim() diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ControllerExtensions.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ControllerExtensions.cs index ad675e41406..0c79a448858 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ControllerExtensions.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ControllerExtensions.cs @@ -39,7 +39,7 @@ internal static async Task SendEmailAsync(this Controller controller, stri { To = email, Subject = subject, - Content = new MailMessageBody { Html = body } + Body = new MailMessageBody { Html = body } }; var result = await smtpService.SendAsync(message); diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/EmailAuthenticatorController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/EmailAuthenticatorController.cs index ca90970acdf..a2673b03a21 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/EmailAuthenticatorController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/EmailAuthenticatorController.cs @@ -101,7 +101,7 @@ public async Task RequestCode() { To = await UserManager.GetEmailAsync(user), Subject = await GetSubjectAsync(settings, user, code), - Content = new MailMessageBody { Html = await GetBodyAsync(settings, user, code) } + Body = new MailMessageBody { Html = await GetBodyAsync(settings, user, code) } }; var result = await _smtpService.SendAsync(message); @@ -172,7 +172,7 @@ public async Task SendCode() { To = await UserManager.GetEmailAsync(user), Subject = await GetSubjectAsync(settings, user, code), - Content = new MailMessageBody { Html = await GetBodyAsync(settings, user, code) } + Body = new MailMessageBody { Html = await GetBodyAsync(settings, user, code) } }; var result = await _smtpService.SendAsync(message); diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Workflows/Activities/RegisterUserTask.cs b/src/OrchardCore.Modules/OrchardCore.Users/Workflows/Activities/RegisterUserTask.cs index 7cf0d11bdba..e1baf02b96b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Workflows/Activities/RegisterUserTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Workflows/Activities/RegisterUserTask.cs @@ -138,7 +138,7 @@ public override async Task ExecuteAsync(WorkflowExecuti { To = email, Subject = subject, - Content = new MailMessageBody { Html = body } + Body = new MailMessageBody { Html = body } }; var smtpService = _httpContextAccessor.HttpContext.RequestServices.GetService(); diff --git a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs index 648504fd346..025ccb06339 100644 --- a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs +++ b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs @@ -46,50 +46,28 @@ public class MailMessage /// public string Subject { get; set; } - /// - /// Gets or sets the message content aka body. - /// - [Obsolete("This property is deprecated, please use Content instead.", true)] - public string Body { get; set; } - /// /// Gets or sets the message content as plain text. /// [Obsolete("This property is deprecated, please use Body instead.", true)] - public string BodyText - { - get => Body; - set - { - Body = value; - IsHtmlBody = false; - } - } + public string BodyText { get; set; } /// /// Gets or sets the message content aka body. /// - public MailMessageBody Content { get; set; } + public MailMessageBody Body { get; set; } /// /// Gets or sets whether the message body is an HTML. /// [Obsolete("This property is deprecated, please use IsHtmlBody instead.", true)] - public bool IsBodyHtml - { - get => IsHtmlBody; - set => IsHtmlBody = value; - } + public bool IsBodyHtml { get; set; } /// /// Gets or sets whether the message body is plain text. /// [Obsolete("This property is deprecated, please use IsHtmlBody instead.", true)] - public bool IsBodyText - { - get => !IsHtmlBody; - set => IsHtmlBody = !value; - } + public bool IsBodyText { get; set; } /// /// Gets or sets whether the message body is an HTML or not. Default is false which is plain text. diff --git a/src/OrchardCore/OrchardCore.Email.Core/Services/SmtpService.cs b/src/OrchardCore/OrchardCore.Email.Core/Services/SmtpService.cs index b33cbae5dff..c7e81e5ece6 100644 --- a/src/OrchardCore/OrchardCore.Email.Core/Services/SmtpService.cs +++ b/src/OrchardCore/OrchardCore.Email.Core/Services/SmtpService.cs @@ -216,8 +216,8 @@ private MimeMessage FromMailMessage(MailMessage message, IList var body = new BodyBuilder { - TextBody = message.Content?.Text, - HtmlBody = message.Content?.Html + TextBody = message.Body?.Text, + HtmlBody = message.Body?.Html }; foreach (var attachment in message.Attachments) diff --git a/src/OrchardCore/OrchardCore.Notifications.Core/Services/EmailNotificationProvider.cs b/src/OrchardCore/OrchardCore.Notifications.Core/Services/EmailNotificationProvider.cs index de14dcfe5f2..09527303a6d 100644 --- a/src/OrchardCore/OrchardCore.Notifications.Core/Services/EmailNotificationProvider.cs +++ b/src/OrchardCore/OrchardCore.Notifications.Core/Services/EmailNotificationProvider.cs @@ -35,15 +35,15 @@ public async Task TrySendAsync(object notify, INotificationMessage message { To = user.Email, Subject = message.Summary, - Content = new MailMessageBody() + Body = new MailMessageBody() }; if (message.IsHtmlPreferred && !string.IsNullOrWhiteSpace(message.HtmlBody)) { - mailMessage.Content.Html = message.HtmlBody; + mailMessage.Body.Html = message.HtmlBody; } else { - mailMessage.Content.Text = message.TextBody; + mailMessage.Body.Text = message.TextBody; } var result = await _smtpService.SendAsync(mailMessage); diff --git a/src/docs/releases/1.8.0.md b/src/docs/releases/1.8.0.md index cea6ed2471a..5190115cb80 100644 --- a/src/docs/releases/1.8.0.md +++ b/src/docs/releases/1.8.0.md @@ -8,6 +8,10 @@ Release date: Not yet released This release removes support for `net6.0` and `net7.0`. Only `net8.0` is supported. +### Email + +The `MailMessage.Body` now returns `MailMessageBody` instead of `string` to support both plain text & HTML formats. + ### TheAdmin Theme The `TheAdmin` theme was upgraded to Bootstrap 5.3.2. Here is a list of the breaking changes diff --git a/test/OrchardCore.Tests/Email/EmailTests.cs b/test/OrchardCore.Tests/Email/EmailTests.cs index a388da002d0..6ce432140ff 100644 --- a/test/OrchardCore.Tests/Email/EmailTests.cs +++ b/test/OrchardCore.Tests/Email/EmailTests.cs @@ -14,7 +14,7 @@ public async Task SendEmail_WithToHeader() { To = "info@oc.com", Subject = "Test", - Content = new MailMessageBody { Text = "Test Message" } + Body = new MailMessageBody { Text = "Test Message" } }; // Act @@ -32,7 +32,7 @@ public async Task SendEmail_WithCcHeader() { Cc = "info@oc.com", Subject = "Test", - Content = new MailMessageBody { Text = "Test Message" } + Body = new MailMessageBody { Text = "Test Message" } }; // Act @@ -50,7 +50,7 @@ public async Task SendEmail_WithBccHeader() { Bcc = "info@oc.com", Subject = "Test", - Content = new MailMessageBody { Text = "Test Message" } + Body = new MailMessageBody { Text = "Test Message" } }; // Act @@ -67,7 +67,7 @@ public async Task SendEmail_WithDisplayName() { To = "info@oc.com", Subject = "Test", - Content = new MailMessageBody { Text = "Test Message" } + Body = new MailMessageBody { Text = "Test Message" } }; await SendEmailAsync(message, "Your Name "); @@ -80,7 +80,7 @@ public async Task SendEmail_UsesDefaultSender() { To = "info@oc.com", Subject = "Test", - Content = new MailMessageBody { Text = "Test Message" } + Body = new MailMessageBody { Text = "Test Message" } }; var content = await SendEmailAsync(message, "Your Name "); @@ -94,7 +94,7 @@ public async Task SendEmail_UsesCustomSender() { To = "info@oc.com", Subject = "Test", - Content = new MailMessageBody { Text = "Test Message" }, + Body = new MailMessageBody { Text = "Test Message" }, From = "My Name ", }; var content = await SendEmailAsync(message, "Your Name "); @@ -110,7 +110,7 @@ public async Task SendEmail_UsesCustomAuthorAndSender() { To = "info@oc.com", Subject = "Test", - Content = new MailMessageBody { Text = "Test Message" }, + Body = new MailMessageBody { Text = "Test Message" }, Sender = "Hisham Bin Ateya ", }; var content = await SendEmailAsync(message, "Sebastien Ros "); @@ -126,7 +126,7 @@ public async Task SendEmail_UsesMultipleAuthors() { To = "info@oc.com", Subject = "Test", - Content = new MailMessageBody { Text = "Test Message" }, + Body = new MailMessageBody { Text = "Test Message" }, From = "sebastienros@gmail.com,hishamco_2007@hotmail.com" }; var content = await SendEmailAsync(message, "Hisham Bin Ateya "); @@ -142,7 +142,7 @@ public async Task SendEmail_UsesReplyTo() { To = "Hisham Bin Ateya ", Subject = "Test", - Content = new MailMessageBody { Text = "Test Message" }, + Body = new MailMessageBody { Text = "Test Message" }, From = "Hisham Bin Ateya ", ReplyTo = "Hisham Bin Ateya ", }; @@ -159,7 +159,7 @@ public async Task ReplyTo_ShouldHaveAuthors_IfNotSet() { To = "info@oc.com", Subject = "Test", - Content = new MailMessageBody { Text = "Test Message" }, + Body = new MailMessageBody { Text = "Test Message" }, From = "Sebastien Ros " }; var content = await SendEmailAsync(message, "Your Name "); @@ -190,7 +190,7 @@ public async Task SendEmail_WithoutToAndCcAndBccHeaders_ShouldThrowsException() var message = new MailMessage { Subject = "Test", - Content = new MailMessageBody { Text = "Test Message" } + Body = new MailMessageBody { Text = "Test Message" } }; var settings = new SmtpSettings { @@ -214,7 +214,7 @@ public async Task SendOfflineEmailHasNoResponse() { To = "info@oc.com", Subject = "Test", - Content = new MailMessageBody { Text = "Test Message" } + Body = new MailMessageBody { Text = "Test Message" } }; var settings = new SmtpSettings { From a0bc7a6e980a313c9e11294892985e1cfc7ed995 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sun, 21 Jan 2024 00:27:04 +0300 Subject: [PATCH 07/24] Remove obsolete memebers --- .../MailMessage.cs | 27 +------------------ 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs index 025ccb06339..90e34505432 100644 --- a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs +++ b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs @@ -1,4 +1,3 @@ -using System; using System.Collections.Generic; namespace OrchardCore.Email @@ -46,38 +45,14 @@ public class MailMessage /// public string Subject { get; set; } - /// - /// Gets or sets the message content as plain text. - /// - [Obsolete("This property is deprecated, please use Body instead.", true)] - public string BodyText { get; set; } - /// /// Gets or sets the message content aka body. /// public MailMessageBody Body { get; set; } - /// - /// Gets or sets whether the message body is an HTML. - /// - [Obsolete("This property is deprecated, please use IsHtmlBody instead.", true)] - public bool IsBodyHtml { get; set; } - - /// - /// Gets or sets whether the message body is plain text. - /// - [Obsolete("This property is deprecated, please use IsHtmlBody instead.", true)] - public bool IsBodyText { get; set; } - - /// - /// Gets or sets whether the message body is an HTML or not. Default is false which is plain text. - /// - [Obsolete("This property is deprecated, please use Content instead.", true)] - public bool IsHtmlBody { get; set; } - /// /// The collection of message attachments. /// - public List Attachments { get; } = new List(); + public List Attachments { get; } = []; } } From 3c079dd5bf4a7399cf5afc572c69b9d05b57b7a9 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sun, 21 Jan 2024 00:27:13 +0300 Subject: [PATCH 08/24] Add release notes docs --- src/docs/releases/1.9.0.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/docs/releases/1.9.0.md b/src/docs/releases/1.9.0.md index 2d846722b0e..1ec486c7b7c 100644 --- a/src/docs/releases/1.9.0.md +++ b/src/docs/releases/1.9.0.md @@ -19,6 +19,10 @@ Previously, the `yessql.db` file was used as a default SQLite database for newly !!! warning For backward compatibility, you should use `yessql.db` as the database name in the `OrchardCore_Data_Sqlite` configuration. For more info read the [Data (`OrchardCore.Data`) documentation](../reference/core/Data/README.md). +### Email Module + +In the past, we use `Body` and `BodyText` to distinguish between the `MailMessage` body format, in this release `MailMessageBody` has been used instead. + ### SMS Module In the past, we utilized the injection of `ISmsProvider`for sending SMS messages. However, in this release, it is now necessary to inject `ISmsService` instead. From b8beb212f09234483eaec81f3e3057b8c64336bd Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Thu, 14 Mar 2024 22:24:55 +0300 Subject: [PATCH 09/24] Fix merge conflict --- .../Services/AzureEmailProviderBase.cs | 12 ++++-------- .../Services/SmtpEmailProviderBase.cs | 13 ++++--------- .../Controllers/AdminController.cs | 2 +- .../Controllers/EmailAuthenticatorController.cs | 12 ++++++++---- 4 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailProviderBase.cs b/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailProviderBase.cs index ea2e2171fb8..719709ade1d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailProviderBase.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailProviderBase.cs @@ -178,15 +178,11 @@ private EmailMessage FromMailMessage(MailMessage message, Dictionary new EmailAddress(r))]; } - var content = new EmailContent(message.Subject); - if (message.IsHtmlBody) + var content = new EmailContent(message.Subject) { - content.Html = message.Body; - } - else - { - content.PlainText = message.Body; - } + PlainText = message.Body?.Text, + Html = message.Body?.Html + }; var emailMessage = new EmailMessage( message.From, diff --git a/src/OrchardCore.Modules/OrchardCore.Email.Smtp/Services/SmtpEmailProviderBase.cs b/src/OrchardCore.Modules/OrchardCore.Email.Smtp/Services/SmtpEmailProviderBase.cs index 56cf283029a..251189d5e9b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email.Smtp/Services/SmtpEmailProviderBase.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email.Smtp/Services/SmtpEmailProviderBase.cs @@ -113,16 +113,11 @@ private MimeMessage GetMimeMessage(MailMessage message) mimeMessage.Subject = message.Subject; - var body = new BodyBuilder(); - - if (message.IsHtmlBody) - { - body.HtmlBody = message.Body; - } - else + var body = new BodyBuilder { - body.TextBody = message.Body; - } + TextBody = message.Body?.Text, + HtmlBody = message.Body?.Html + }; foreach (var attachment in message.Attachments) { diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Email/Controllers/AdminController.cs index 51e4120a113..affdf7622e3 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email/Controllers/AdminController.cs @@ -134,7 +134,7 @@ private static MailMessage GetMessage(EmailTestViewModel testSettings) if (!string.IsNullOrWhiteSpace(testSettings.Body)) { - message.Body = testSettings.Body; + message.Body = new MailMessageBody { Text = testSettings.Body }; } return message; diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/EmailAuthenticatorController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/EmailAuthenticatorController.cs index 2a692bdb5d0..1baaa04cde6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/EmailAuthenticatorController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/EmailAuthenticatorController.cs @@ -101,8 +101,10 @@ public async Task RequestCode() { To = await UserManager.GetEmailAsync(user), Subject = await GetSubjectAsync(settings, user, code), - Body = await GetBodyAsync(settings, user, code), - IsHtmlBody = true, + Body = new MailMessageBody + { + Html = await GetBodyAsync(settings, user, code) + } }; var result = await _emailService.SendAsync(message); @@ -174,8 +176,10 @@ public async Task SendCode() { To = await UserManager.GetEmailAsync(user), Subject = await GetSubjectAsync(settings, user, code), - Body = await GetBodyAsync(settings, user, code), - IsHtmlBody = true, + Body = new MailMessageBody + { + Html = await GetBodyAsync(settings, user, code) + } }; var result = await _emailService.SendAsync(message); From 0ea8cd1a3bdbda4531d8538a56734472b9b44a2d Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sat, 23 Mar 2024 00:20:24 +0300 Subject: [PATCH 10/24] Update src/docs/releases/1.9.0.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Zoltán Lehóczky --- src/docs/releases/1.9.0.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/docs/releases/1.9.0.md b/src/docs/releases/1.9.0.md index f39edf14dd4..c811f54a2a9 100644 --- a/src/docs/releases/1.9.0.md +++ b/src/docs/releases/1.9.0.md @@ -72,7 +72,11 @@ If you need to enable indexing for other extensions like (`.docx`, or `.pptx`), ### Email Module -In the past, we use `Body` and `BodyText` to distinguish between the `MailMessage` body format, in this release `MailMessageBody` has been used instead. +Previously, emails sent from Orchard Core could have either a plain text body, or an HTML body, but not both. Now, they can have both. This also brings some code-level API changes, see below. + +When interacting with email-related services from code, `MailMessage`, the class representing an e-mail, exposed a `string` `Body` property. This could contain either plain text or HTML, which was indicated by `IsHtmlBody`. + +While this API is still available, it's deprecated in favor of the new `Body` property that uses the new `MailMessageBody` type. This can contain a plain text and/or HTML body. ### SMS Module From c86399f49dea89bcd64448883e8ebdf8ebb58a50 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Mon, 17 Jun 2024 18:00:53 +0300 Subject: [PATCH 11/24] Add implicit operator to MailMessageBody --- .../MailMessageBody.cs | 6 +++++ test/OrchardCore.Tests/Email/EmailTests.cs | 22 +++++++++---------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageBody.cs b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageBody.cs index 6553aa4b4ea..68a29c2313c 100644 --- a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageBody.cs +++ b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageBody.cs @@ -14,4 +14,10 @@ public class MailMessageBody /// Gets or sets the body in HTML format. /// public string Html { get; set; } + + public static implicit operator MailMessageBody(string body) => new() + { + Html = body, + Text = body + }; } diff --git a/test/OrchardCore.Tests/Email/EmailTests.cs b/test/OrchardCore.Tests/Email/EmailTests.cs index a1cf317c329..f376c30d50b 100644 --- a/test/OrchardCore.Tests/Email/EmailTests.cs +++ b/test/OrchardCore.Tests/Email/EmailTests.cs @@ -14,7 +14,7 @@ public async Task SendEmail_UsesDefaultSender() { To = "info@oc.com", Subject = "Test", - Body = new MailMessageBody { Html = "Test Message" } + Body = "Test Message" }; // Act @@ -32,7 +32,7 @@ public async Task SendEmail_WithCcHeader() { Cc = "info@oc.com", Subject = "Test", - Body = new MailMessageBody { Html = "Test Message" } + Body = "Test Message" }; // Act @@ -50,7 +50,7 @@ public async Task SendEmail_WithBccHeader() { Bcc = "info@oc.com", Subject = "Test", - Body = new MailMessageBody { Html = "Test Message" } + Body = "Test Message" }; // Act @@ -67,7 +67,7 @@ public async Task SendEmail_WithDisplayName() { To = "info@oc.com", Subject = "Test", - Body = new MailMessageBody { Html = "Test Message" } + Body = "Test Message" }; await SendEmailAsync(message, "Your Name "); @@ -80,7 +80,7 @@ public async Task SendEmail_UsesCustomSender() { To = "info@oc.com", Subject = "Test", - Body = new MailMessageBody { Html = "Test Message" }, + Body = "Test Message", From = "My Name ", }; var content = await SendEmailAsync(message, "Your Name "); @@ -96,7 +96,7 @@ public async Task SendEmail_UsesCustomAuthorAndSender() { To = "info@oc.com", Subject = "Test", - Body = new MailMessageBody { Html = "Test Message" }, + Body = "Test Message", Sender = "Hisham Bin Ateya ", }; var content = await SendEmailAsync(message, "Sebastien Ros "); @@ -112,7 +112,7 @@ public async Task SendEmail_UsesMultipleAuthors() { To = "info@oc.com", Subject = "Test", - Body = new MailMessageBody { Html = "Test Message" }, + Body = "Test Message", From = "sebastienros@gmail.com,hishamco_2007@hotmail.com" }; var content = await SendEmailAsync(message, "Hisham Bin Ateya "); @@ -128,7 +128,7 @@ public async Task SendEmail_UsesReplyTo() { To = "Hisham Bin Ateya ", Subject = "Test", - Body = new MailMessageBody { Html = "Test Message" }, + Body = "Test Message", From = "Hisham Bin Ateya ", ReplyTo = "Hisham Bin Ateya ", }; @@ -145,7 +145,7 @@ public async Task ReplyTo_ShouldHaveAuthors_IfNotSet() { To = "info@oc.com", Subject = "Test", - Body = new MailMessageBody { Html = "Test Message" }, + Body = "Test Message", From = "Sebastien Ros " }; var content = await SendEmailAsync(message, "Your Name "); @@ -176,7 +176,7 @@ public async Task SendEmail_WithoutToAndCcAndBccHeaders_ShouldThrowsException() var message = new MailMessage { Subject = "Test", - Body = new MailMessageBody { Html = "Test Message" } + Body = "Test Message" }; var options = new SmtpOptions @@ -201,7 +201,7 @@ public async Task SendOfflineEmailHasNoResponse() { To = "info@oc.com", Subject = "Test", - Body = new MailMessageBody { Html = "Test Message" } + Body = "Test Message" }; var settings = new SmtpOptions { From d1f6ce739accc148dbc8aa53d61d4efe3783ad39 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Mon, 17 Jun 2024 18:47:33 +0300 Subject: [PATCH 12/24] Text -> PlainText --- .../Services/AzureEmailProviderBase.cs | 2 +- .../OrchardCore.Email.Smtp/Services/SmtpEmailProviderBase.cs | 2 +- .../OrchardCore.Email/Controllers/AdminController.cs | 2 +- .../OrchardCore.Email/Workflows/Activities/EmailTask.cs | 2 +- .../Extensions/EmailServiceExtensions.cs | 2 +- .../OrchardCore.Email.Abstractions/MailMessageBody.cs | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailProviderBase.cs b/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailProviderBase.cs index 42d0c057f1e..b38b86be54e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailProviderBase.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailProviderBase.cs @@ -180,7 +180,7 @@ private EmailMessage FromMailMessage(MailMessage message, Dictionary ExecuteAsync(WorkflowExecuti Subject = subject?.Trim(), Body = new MailMessageBody { - Text = textBody?.Trim(), + PlainText = textBody?.Trim(), Html = htmlBody?.Trim() } }; diff --git a/src/OrchardCore/OrchardCore.Email.Abstractions/Extensions/EmailServiceExtensions.cs b/src/OrchardCore/OrchardCore.Email.Abstractions/Extensions/EmailServiceExtensions.cs index e6a4474511e..cbb4a7fe63e 100644 --- a/src/OrchardCore/OrchardCore.Email.Abstractions/Extensions/EmailServiceExtensions.cs +++ b/src/OrchardCore/OrchardCore.Email.Abstractions/Extensions/EmailServiceExtensions.cs @@ -25,7 +25,7 @@ public static Task SendAsync(this IEmailService emailService, strin Body = new MailMessageBody { Html = htmlBody, - Text = textBody + PlainText = textBody } }; diff --git a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageBody.cs b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageBody.cs index 68a29c2313c..49413b88370 100644 --- a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageBody.cs +++ b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageBody.cs @@ -8,7 +8,7 @@ public class MailMessageBody /// /// Gets or sets the body in plain text format. /// - public string Text { get; set; } + public string PlainText { get; set; } /// /// Gets or sets the body in HTML format. @@ -18,6 +18,6 @@ public class MailMessageBody public static implicit operator MailMessageBody(string body) => new() { Html = body, - Text = body + PlainText = body }; } From e964ff9e8ffc9c489a39d193783bd86c5fb74819 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sat, 4 Jan 2025 12:35:52 +0300 Subject: [PATCH 13/24] Fix the build --- .../MailMessage.cs | 105 +++++++++--------- 1 file changed, 51 insertions(+), 54 deletions(-) diff --git a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs index b363f431be1..735ee86d23e 100644 --- a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs +++ b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs @@ -1,58 +1,55 @@ -using System.Collections.Generic; +namespace OrchardCore.Email; -namespace OrchardCore.Email +/// +/// Represents a class that contains information of the mail message. +/// +public class MailMessage { /// - /// Represents a class that contains information of the mail message. - /// - public class MailMessage - { - /// - /// Gets or sets the author of the email. - /// - public string From { get; set; } - - /// - /// Gets or sets the recipients. - /// - public string To { get; set; } - - /// - /// Gets or sets the carbon copy emails. - /// - public string Cc { get; set; } - - /// - /// Gets or sets a blind copy emails. - /// - public string Bcc { get; set; } - - /// - /// Gets or sets the replied to emails. - /// - public string ReplyTo { get; set; } - - /// - /// Gets or sets the actual submitter of the email. - /// - /// - /// This property is required if not the same as , for more information please refer to https://ietf.org/rfc/rfc822.txt. - /// - public string Sender { get; set; } - - /// - /// Gets or sets the message subject. - /// - public string Subject { get; set; } - - /// - /// Gets or sets the message content aka body. - /// - public MailMessageBody Body { get; set; } - - /// - /// The collection of message attachments. - /// - public List Attachments { get; init; } = []; - } + /// Gets or sets the author of the email. + /// + public string From { get; set; } + + /// + /// Gets or sets the recipients. + /// + public string To { get; set; } + + /// + /// Gets or sets the carbon copy emails. + /// + public string Cc { get; set; } + + /// + /// Gets or sets a blind copy emails. + /// + public string Bcc { get; set; } + + /// + /// Gets or sets the replied to emails. + /// + public string ReplyTo { get; set; } + + /// + /// Gets or sets the actual submitter of the email. + /// + /// + /// This property is required if not the same as , for more information please refer to https://ietf.org/rfc/rfc822.txt. + /// + public string Sender { get; set; } + + /// + /// Gets or sets the message subject. + /// + public string Subject { get; set; } + + /// + /// Gets or sets the message content aka body. + /// + public MailMessageBody Body { get; set; } + + /// + /// The collection of message attachments. + /// + public List Attachments { get; init; } = []; } From c06593325e0e29042cec82cb0a30b284de67d49d Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Wed, 22 Jan 2025 02:01:57 +0300 Subject: [PATCH 14/24] Move docs to 3.0.0 --- src/docs/releases/1.8.0.md | 4 ---- src/docs/releases/2.0.0.md | 8 -------- src/docs/releases/3.0.0.md | 8 ++++++++ 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/docs/releases/1.8.0.md b/src/docs/releases/1.8.0.md index 8a0a8115b6c..7c44183be40 100644 --- a/src/docs/releases/1.8.0.md +++ b/src/docs/releases/1.8.0.md @@ -12,10 +12,6 @@ The interface `OrchardCore.Documents.IDocumentSerialiser` has been renamed to `O This release removes support for `net6.0` and `net7.0`. Only `net8.0` is supported. -### Email - -The `MailMessage.Body` now returns `MailMessageBody` instead of `string` to support both plain text & HTML formats. - ### TheAdmin Theme The `TheAdmin` theme was upgraded to Bootstrap 5.3.2. Here is a list of the breaking changes diff --git a/src/docs/releases/2.0.0.md b/src/docs/releases/2.0.0.md index a18eadae056..82ee65d4820 100644 --- a/src/docs/releases/2.0.0.md +++ b/src/docs/releases/2.0.0.md @@ -95,14 +95,6 @@ services.AddJsonDerivedTypeInfo(); } ``` -### Email Module - -Previously, emails sent from Orchard Core could have either a plain text body, or an HTML body, but not both. Now, they can have both. This also brings some code-level API changes, see below. - -When interacting with email-related services from code, `MailMessage`, the class representing an e-mail, exposed a `string` `Body` property. This could contain either plain text or HTML, which was indicated by `IsHtmlBody`. - -While this API is still available, it's deprecated in favor of the new `Body` property that uses the new `MailMessageBody` type. This can contain a plain text and/or HTML body. - ### Queries Previously, any query type had to inherit from `Query` and required its own distinct type (e.g., `SqlQuery`, `LuceneQuery`, `ElasticQuery`). However, with [pull request #16402](https://github.com/OrchardCMS/OrchardCore/pull/16402), creating a custom type for each query type is no longer necessary. This update involved changes to the `IQueryManager` and `IQuerySource` interfaces, as well as the `Query` class. Additionally, a new project, `OrchardCore.Queries.Core`, was introduced. diff --git a/src/docs/releases/3.0.0.md b/src/docs/releases/3.0.0.md index ccbac4db9d4..87957a25831 100644 --- a/src/docs/releases/3.0.0.md +++ b/src/docs/releases/3.0.0.md @@ -6,6 +6,14 @@ Before upgrading from version 2 to v3, it is important to first compile your pro ## Breaking Changes +### Email Module + +Previously, emails sent from Orchard Core could have either a plain text body, or an HTML body, but not both. Now, they can have both. This also brings some code-level API changes, see below. + +When interacting with email-related services from code, `MailMessage`, the class representing an e-mail, exposed a `string` `Body` property. This could contain either plain text or HTML, which was indicated by `IsHtmlBody`. + +While this API is still available, it's deprecated in favor of the new `Body` property that uses the new `MailMessageBody` type. This can contain a plain text and/or HTML body. + ### GraphQL Module #### GraphQL Library Upgrade From 8127588ecf6237eb05419d7b4ded07f10911cf8d Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sat, 25 Jan 2025 04:25:32 +0300 Subject: [PATCH 15/24] Fix message formats dropdown list --- .../OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml index 3fba214e6ae..d6b60225f78 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml @@ -104,7 +104,7 @@ mode: { name: "liquid" }, }); - $('select').onchange(function () { + $('select').on('change', function () { var selectedValue = $(this).val(); switch (selectedValue) { case '@MailMessageFormat.Text': From e11b9ab8dec932c18ce8a3046824ea04391a99dc Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Fri, 31 Jan 2025 03:16:10 +0300 Subject: [PATCH 16/24] Backward compatibility --- .../Workflows/Activities/EmailTask.cs | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs index b3fe82b834e..14aed89fc33 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs @@ -74,15 +74,49 @@ public WorkflowExpression Subject set => SetProperty(value); } - public WorkflowExpression TextBody + [Obsolete("This property is deprecated, please use TextBody & HtmlBody instead.")] + public WorkflowExpression Body { get => GetProperty(() => new WorkflowExpression()); set => SetProperty(value); } + [Obsolete("This property is deprecated, please use TextBody & HtmlBody instead.")] + public bool IsHtmlBody + { + get => GetProperty(() => true); + set => SetProperty(value); + } + + public WorkflowExpression TextBody + { + get + { + var textBody = GetProperty>(); + + if (textBody == null && !GetProperty(() => true, "IsHtmlBody")) + { + textBody = GetProperty(() => new WorkflowExpression(), "Body"); + } + + return textBody ?? new WorkflowExpression(); + } + set => SetProperty(value); + } + public WorkflowExpression HtmlBody { - get => GetProperty(() => new WorkflowExpression()); + get + { + var htmlBody = GetProperty>(); + + if (htmlBody == null && GetProperty(() => true, "IsHtmlBody")) + { + htmlBody = GetProperty(() => new WorkflowExpression(), "Body"); + } + + return htmlBody ?? new WorkflowExpression(); + } set => SetProperty(value); } From daaf9dcbc46ec8254483f0c6b0682381073b101b Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Fri, 31 Jan 2025 03:55:52 +0300 Subject: [PATCH 17/24] Update src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml Co-authored-by: Georg von Kries --- .../Views/Items/EmailTask.Fields.Edit.cshtml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml index d6b60225f78..0077e904e49 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml @@ -112,8 +112,8 @@ $('#htmlBody').addClass('d-none'); break; case '@MailMessageFormat.Html': - $('#textBody').removeClass('d-none'); - $('#htmlBody').addClass('d-none'); + $('#textBody').addClass('d-none'); + $('#htmlBody').removeClass('d-none'); break; case '@MailMessageFormat.All': $('#textBody').removeClass('d-none'); From d228031e182c75d21062989670c577d59c036fc5 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Fri, 31 Jan 2025 03:57:09 +0300 Subject: [PATCH 18/24] Update src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml Co-authored-by: Georg von Kries --- .../Views/Items/EmailTask.Fields.Edit.cshtml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml index 0077e904e49..a8017ee0782 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml @@ -62,9 +62,9 @@
@T["The format of the email message."]
From e8171428e89409fe8f50b8cefa4c33139a475f76 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sat, 1 Feb 2025 20:46:02 +0300 Subject: [PATCH 19/24] Change docs --- src/docs/releases/3.0.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/docs/releases/3.0.0.md b/src/docs/releases/3.0.0.md index 294956260ef..2e8a066fabc 100644 --- a/src/docs/releases/3.0.0.md +++ b/src/docs/releases/3.0.0.md @@ -12,7 +12,7 @@ Previously, emails sent from Orchard Core could have either a plain text body, o When interacting with email-related services from code, `MailMessage`, the class representing an e-mail, exposed a `string` `Body` property. This could contain either plain text or HTML, which was indicated by `IsHtmlBody`. -While this API is still available, it's deprecated in favor of the new `Body` property that uses the new `MailMessageBody` type. This can contain a plain text and/or HTML body. +The new `Body` property returns `MailMessageBody` type, which contains a plain text and/or HTML body. ### GraphQL Module From 24eb63056f9d786692a16e849374972fd150502e Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sat, 8 Feb 2025 21:14:36 +0300 Subject: [PATCH 20/24] Split into TextBody & HtmlBody properties --- .../Services/AzureEmailProviderBase.cs | 4 ++-- .../Services/SmtpEmailProviderBase.cs | 4 ++-- .../Controllers/AdminController.cs | 2 +- .../Workflows/Activities/EmailTask.cs | 7 ++---- .../Extensions/EmailServiceExtensions.cs | 7 ++---- .../MailMessage.cs | 15 ++++++++++-- .../MailMessageBody.cs | 23 ------------------- test/OrchardCore.Tests/Email/EmailTests.cs | 22 +++++++++--------- 8 files changed, 33 insertions(+), 51 deletions(-) delete mode 100644 src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageBody.cs diff --git a/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailProviderBase.cs b/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailProviderBase.cs index a3ebd107655..24972e21b6b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailProviderBase.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailProviderBase.cs @@ -200,8 +200,8 @@ private EmailMessage FromMailMessage(MailMessage message, Dictionary ExecuteAsync(WorkflowExecuti // Email reply-to header https://tools.ietf.org/html/rfc4021#section-2.1.4 ReplyTo = replyTo?.Trim(), Subject = subject?.Trim(), - Body = new MailMessageBody - { - PlainText = textBody?.Trim(), - Html = htmlBody?.Trim() - } + HtmlBody = htmlBody?.Trim(), + TextBody = textBody?.Trim() }; if (!string.IsNullOrWhiteSpace(sender)) diff --git a/src/OrchardCore/OrchardCore.Email.Abstractions/Extensions/EmailServiceExtensions.cs b/src/OrchardCore/OrchardCore.Email.Abstractions/Extensions/EmailServiceExtensions.cs index b255ec00058..782264fffc1 100644 --- a/src/OrchardCore/OrchardCore.Email.Abstractions/Extensions/EmailServiceExtensions.cs +++ b/src/OrchardCore/OrchardCore.Email.Abstractions/Extensions/EmailServiceExtensions.cs @@ -20,11 +20,8 @@ public static Task SendAsync(this IEmailService emailService, strin { To = to, Subject = subject, - Body = new MailMessageBody - { - Html = htmlBody, - PlainText = textBody - } + HtmlBody = htmlBody, + TextBody = textBody }; return emailService.SendAsync(message); diff --git a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs index 735ee86d23e..51884a300a1 100644 --- a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs +++ b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs @@ -43,10 +43,21 @@ public class MailMessage /// public string Subject { get; set; } + [Obsolete("This property has been deprecated, please use the HtmlBody or TextBody property instead.")] + public bool IsHtmlBody { get; set; } + + [Obsolete("This property has been deprecated, please use the HtmlBody or TextBody property instead.")] + public string Body { get; set; } + + /// + /// Gets or sets the message content in HTML format. + /// + public string HtmlBody { get; set; } + /// - /// Gets or sets the message content aka body. + /// Gets or sets the message content in plain text format. /// - public MailMessageBody Body { get; set; } + public string TextBody { get; set; } /// /// The collection of message attachments. diff --git a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageBody.cs b/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageBody.cs deleted file mode 100644 index 49413b88370..00000000000 --- a/src/OrchardCore/OrchardCore.Email.Abstractions/MailMessageBody.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace OrchardCore.Email; - -/// -/// Represents a body for . -/// -public class MailMessageBody -{ - /// - /// Gets or sets the body in plain text format. - /// - public string PlainText { get; set; } - - /// - /// Gets or sets the body in HTML format. - /// - public string Html { get; set; } - - public static implicit operator MailMessageBody(string body) => new() - { - Html = body, - PlainText = body - }; -} diff --git a/test/OrchardCore.Tests/Email/EmailTests.cs b/test/OrchardCore.Tests/Email/EmailTests.cs index bb0f397801f..33fce5739ce 100644 --- a/test/OrchardCore.Tests/Email/EmailTests.cs +++ b/test/OrchardCore.Tests/Email/EmailTests.cs @@ -14,7 +14,7 @@ public async Task SendEmail_UsesDefaultSender() { To = "info@oc.com", Subject = "Test", - Body = "Test Message" + TextBody = "Test Message" }; // Act @@ -32,7 +32,7 @@ public async Task SendEmail_WithCcHeader() { Cc = "info@oc.com", Subject = "Test", - Body = "Test Message" + TextBody = "Test Message" }; // Act @@ -50,7 +50,7 @@ public async Task SendEmail_WithBccHeader() { Bcc = "info@oc.com", Subject = "Test", - Body = "Test Message" + TextBody = "Test Message" }; // Act @@ -67,7 +67,7 @@ public async Task SendEmail_WithDisplayName() { To = "info@oc.com", Subject = "Test", - Body = "Test Message" + TextBody = "Test Message" }; await SendEmailAsync(message, "Your Name "); @@ -80,7 +80,7 @@ public async Task SendEmail_UsesCustomSender() { To = "info@oc.com", Subject = "Test", - Body = "Test Message", + TextBody = "Test Message", From = "My Name ", }; var content = await SendEmailAsync(message, "Your Name "); @@ -96,7 +96,7 @@ public async Task SendEmail_UsesCustomAuthorAndSender() { To = "info@oc.com", Subject = "Test", - Body = "Test Message", + TextBody = "Test Message", Sender = "Hisham Bin Ateya ", }; var content = await SendEmailAsync(message, "Sebastien Ros "); @@ -112,7 +112,7 @@ public async Task SendEmail_UsesMultipleAuthors() { To = "info@oc.com", Subject = "Test", - Body = "Test Message", + TextBody = "Test Message", From = "sebastienros@gmail.com,hishamco_2007@hotmail.com" }; var content = await SendEmailAsync(message, "Hisham Bin Ateya "); @@ -128,7 +128,7 @@ public async Task SendEmail_UsesReplyTo() { To = "Hisham Bin Ateya ", Subject = "Test", - Body = "Test Message", + TextBody = "Test Message", From = "Hisham Bin Ateya ", ReplyTo = "Hisham Bin Ateya ", }; @@ -145,7 +145,7 @@ public async Task ReplyTo_ShouldHaveAuthors_IfNotSet() { To = "info@oc.com", Subject = "Test", - Body = "Test Message", + TextBody = "Test Message", From = "Sebastien Ros " }; var content = await SendEmailAsync(message, "Your Name "); @@ -176,7 +176,7 @@ public async Task SendEmail_WithoutToAndCcAndBccHeaders_ShouldThrowsException() var message = new MailMessage { Subject = "Test", - Body = "Test Message" + TextBody = "Test Message" }; var options = new SmtpOptions @@ -201,7 +201,7 @@ public async Task SendOfflineEmailHasNoResponse() { To = "info@oc.com", Subject = "Test", - Body = "Test Message" + TextBody = "Test Message" }; var settings = new SmtpOptions { From e250ee4a328b09fde6a2a58f92ed1b9dd6980b32 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sat, 8 Feb 2025 21:26:10 +0300 Subject: [PATCH 21/24] Add unit test --- test/OrchardCore.Tests/Email/EmailTests.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/test/OrchardCore.Tests/Email/EmailTests.cs b/test/OrchardCore.Tests/Email/EmailTests.cs index 33fce5739ce..6e2db137da8 100644 --- a/test/OrchardCore.Tests/Email/EmailTests.cs +++ b/test/OrchardCore.Tests/Email/EmailTests.cs @@ -217,6 +217,28 @@ public async Task SendOfflineEmailHasNoResponse() Assert.Null(result.Response); } + [Fact] + public async Task SendEmail_WithTextAndHtmlFormats() + { + // Arrange + var message = new MailMessage + { + To = "info@oc.com", + Subject = "Test", + TextBody = "Plain text Message", + HtmlBody = "

HTML Message

" + }; + + // Act + var content = await SendEmailAsync(message); + + // Assert + Assert.Contains("Content-Type: text/plain; charset=utf-8", content); + Assert.Contains("Plain text Message", content); + Assert.Contains("Content-Type: text/html; charset=utf-8", content); + Assert.Contains("

HTML Message

", content); + } + private static async Task SendEmailAsync(MailMessage message, string defaultSender = null) { var pickupDirectoryPath = Path.Combine(Directory.GetCurrentDirectory(), "Email"); From 3a5bca5ef69e48b4a028e9cf7d807685524be43a Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Mon, 10 Feb 2025 02:26:09 +0300 Subject: [PATCH 22/24] Update src/docs/releases/3.0.0.md Co-authored-by: Georg von Kries --- src/docs/releases/3.0.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/docs/releases/3.0.0.md b/src/docs/releases/3.0.0.md index 2e8a066fabc..4026b466d54 100644 --- a/src/docs/releases/3.0.0.md +++ b/src/docs/releases/3.0.0.md @@ -12,7 +12,7 @@ Previously, emails sent from Orchard Core could have either a plain text body, o When interacting with email-related services from code, `MailMessage`, the class representing an e-mail, exposed a `string` `Body` property. This could contain either plain text or HTML, which was indicated by `IsHtmlBody`. -The new `Body` property returns `MailMessageBody` type, which contains a plain text and/or HTML body. +These two properties have now been replaced by the `TextBody` and `HtmlBody` properties, which contains a plain text and/or HTML body. ### GraphQL Module From fa5d5baddd82eb9ed6228a8093b9423e854cf4c1 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Fri, 14 Feb 2025 03:09:09 +0300 Subject: [PATCH 23/24] Address feedback --- .../Extensions/EmailServiceExtensions.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OrchardCore/OrchardCore.Email.Abstractions/Extensions/EmailServiceExtensions.cs b/src/OrchardCore/OrchardCore.Email.Abstractions/Extensions/EmailServiceExtensions.cs index 782264fffc1..0646f3317e9 100644 --- a/src/OrchardCore/OrchardCore.Email.Abstractions/Extensions/EmailServiceExtensions.cs +++ b/src/OrchardCore/OrchardCore.Email.Abstractions/Extensions/EmailServiceExtensions.cs @@ -11,8 +11,8 @@ public static class EmailServiceExtensions /// The . /// The email recipients. /// The email subject. - /// The email body in HTML format. - /// The email body in Text format. + /// An optional email body in HTML format. + /// An optional email body in Text format. /// public static Task SendAsync(this IEmailService emailService, string to, string subject, string htmlBody, string textBody) { @@ -35,7 +35,7 @@ public static Task SendAsync(this IEmailService emailService, strin /// The email subject. /// The email body. /// Whether the is in HTML format or not. Defaults to true. - /// + /// public static async Task SendAsync(this IEmailService emailService, string to, string subject, string body, bool isHtmlBody = true) { string htmlBody = default; From 5e48b15f4d8e4c90a9a1888026baa8ef2e4f1db7 Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Sat, 15 Feb 2025 08:54:41 +0300 Subject: [PATCH 24/24] Address feedback --- .../Views/Items/EmailTask.Fields.Edit.cshtml | 66 ++++++++----------- .../Workflows/Activities/EmailTask.cs | 6 ++ .../Drivers/EmailTaskDisplayDriver.cs | 2 + .../Workflows/MailMessageBodyFormat.cs | 8 +++ .../ViewModels/EmailTaskViewModel.cs | 2 + 5 files changed, 47 insertions(+), 37 deletions(-) create mode 100644 src/OrchardCore.Modules/OrchardCore.Email/Workflows/MailMessageBodyFormat.cs diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml b/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml index a8017ee0782..e208e670990 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Email/Views/Items/EmailTask.Fields.Edit.cshtml @@ -1,14 +1,6 @@ +@using OrchardCore.Email.Workflows @using OrchardCore.Email.Workflows.ViewModels @model EmailTaskViewModel -@functions -{ - private enum MailMessageFormat - { - Text, - Html, - All - } -}
@@ -61,21 +53,21 @@
- + + + @T["The format of the email message."]
-
+
@T["The plain text body of the email message. With Liquid support."]
-
+
@T["The HTML body of the email message. With Liquid support."] @@ -91,35 +83,35 @@ diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs index 6b6ca45cb7c..beb6716a874 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Activities/EmailTask.cs @@ -88,6 +88,12 @@ public bool IsHtmlBody set => SetProperty(value); } + public MailMessageBodyFormat BodyFormat + { + get => GetProperty(() => MailMessageBodyFormat.All); + set => SetProperty(value); + } + public WorkflowExpression TextBody { get diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Drivers/EmailTaskDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Drivers/EmailTaskDisplayDriver.cs index 85fae870666..eae21e6f854 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Drivers/EmailTaskDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/Drivers/EmailTaskDisplayDriver.cs @@ -14,6 +14,7 @@ protected override void EditActivity(EmailTask activity, EmailTaskViewModel mode model.RecipientsExpression = activity.Recipients.Expression; model.ReplyToExpression = activity.ReplyTo.Expression; model.SubjectExpression = activity.Subject.Expression; + model.BodyFormat = activity.BodyFormat; model.TextBody = activity.TextBody.Expression; model.HtmlBody = activity.HtmlBody.Expression; model.BccExpression = activity.Bcc.Expression; @@ -27,6 +28,7 @@ protected override void UpdateActivity(EmailTaskViewModel model, EmailTask activ activity.Recipients = new WorkflowExpression(model.RecipientsExpression); activity.ReplyTo = new WorkflowExpression(model.ReplyToExpression); activity.Subject = new WorkflowExpression(model.SubjectExpression); + activity.BodyFormat = model.BodyFormat; activity.TextBody = new WorkflowExpression(model.TextBody); activity.HtmlBody = new WorkflowExpression(model.HtmlBody); activity.Bcc = new WorkflowExpression(model.BccExpression); diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/MailMessageBodyFormat.cs b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/MailMessageBodyFormat.cs new file mode 100644 index 00000000000..78ce5a3a610 --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/MailMessageBodyFormat.cs @@ -0,0 +1,8 @@ +namespace OrchardCore.Email.Workflows; + +public enum MailMessageBodyFormat +{ + All, + Text, + Html, +} diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/ViewModels/EmailTaskViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/ViewModels/EmailTaskViewModel.cs index 4b44afb5653..8408f750cba 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Workflows/ViewModels/EmailTaskViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email/Workflows/ViewModels/EmailTaskViewModel.cs @@ -16,6 +16,8 @@ public class EmailTaskViewModel public string SubjectExpression { get; set; } + public MailMessageBodyFormat BodyFormat { get; set; } + public string TextBody { get; set; } public string HtmlBody { get; set; }