-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support both Text & HTML in the same email #14715
base: main
Are you sure you want to change the base?
Changes from 13 commits
d492809
fefd6ff
57403f1
9d56318
9f52deb
5843a39
a587476
dd37fd1
a0bc7a6
3c079dd
4f8b04f
2d953d7
b8beb21
0ea8cd1
c3a546d
5952079
c86399f
d1f6ce7
279ae07
55aa5d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,15 +76,15 @@ public WorkflowExpression<string> Subject | |
set => SetProperty(value); | ||
} | ||
|
||
public WorkflowExpression<string> Body | ||
public WorkflowExpression<string> TextBody | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea is to generate both bodies, so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the consumers of the old API, nothing will change. For the consumers of the new API, |
||
{ | ||
get => GetProperty(() => new WorkflowExpression<string>()); | ||
set => SetProperty(value); | ||
} | ||
|
||
public bool IsHtmlBody | ||
public WorkflowExpression<string> HtmlBody | ||
{ | ||
get => GetProperty(() => true); | ||
get => GetProperty(() => new WorkflowExpression<string>()); | ||
set => SetProperty(value); | ||
} | ||
|
||
|
@@ -102,7 +102,8 @@ public override async Task<ActivityExecutionResult> 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 textBody = await _expressionEvaluator.EvaluateAsync(TextBody, workflowContext, null); | ||
var htmlBody = await _expressionEvaluator.EvaluateAsync(HtmlBody, workflowContext, _htmlEncoder); | ||
|
||
var message = new MailMessage | ||
{ | ||
|
@@ -114,8 +115,11 @@ public override async Task<ActivityExecutionResult> 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(), | ||
IsHtmlBody = IsHtmlBody | ||
Body = new MailMessageBody | ||
{ | ||
Text = textBody?.Trim(), | ||
Html = htmlBody?.Trim() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you checked that actually both are sent if both are provided? |
||
} | ||
}; | ||
|
||
if (!string.IsNullOrWhiteSpace(sender)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.IsHtmlBody = activity.IsHtmlBody; | ||
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<string>(model.RecipientsExpression); | ||
activity.ReplyTo = new WorkflowExpression<string>(model.ReplyToExpression); | ||
activity.Subject = new WorkflowExpression<string>(model.SubjectExpression); | ||
activity.Body = new WorkflowExpression<string>(model.Body); | ||
activity.IsHtmlBody = model.IsHtmlBody; | ||
activity.TextBody = new WorkflowExpression<string>(model.TextBody); | ||
activity.HtmlBody = new WorkflowExpression<string>(model.HtmlBody); | ||
Comment on lines
+30
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With this logic, if you switch from Text to HTML (not All), for example, then the old Text value will still exist, and will be used, even though you won't see it and won't be able to edit it on the UI. |
||
activity.Bcc = new WorkflowExpression<string>(model.BccExpression); | ||
activity.Cc = new WorkflowExpression<string>(model.CcExpression); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace OrchardCore.Email | ||
|
@@ -49,47 +48,7 @@ public class MailMessage | |
/// <summary> | ||
/// Gets or sets the message content aka body. | ||
/// </summary> | ||
/// <remarks>This property is work in conjunction with <see cref="IsHtmlBody"/> to determine the body type..</remarks> | ||
public string Body { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the message content as plain text. | ||
/// </summary> | ||
[Obsolete("This property is deprecated, please use Body instead.")] | ||
public string BodyText | ||
{ | ||
get => Body; | ||
set | ||
{ | ||
Body = value; | ||
IsHtmlBody = false; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets whether the message body is an HTML. | ||
/// </summary> | ||
[Obsolete("This property is deprecated, please use IsHtmlBody instead.")] | ||
public bool IsBodyHtml | ||
{ | ||
get => IsHtmlBody; | ||
set => IsHtmlBody = value; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets whether the message body is plain text. | ||
/// </summary> | ||
[Obsolete("This property is deprecated, please use IsHtmlBody instead.")] | ||
public bool IsBodyText | ||
{ | ||
get => !IsHtmlBody; | ||
set => IsHtmlBody = !value; | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets whether the message body is an HTML or not. Default is <c>false</c> which is plain text. | ||
/// </summary> | ||
public bool IsHtmlBody { get; set; } | ||
public MailMessageBody Body { get; set; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this is a published interface, keep the old properties with |
||
|
||
/// <summary> | ||
/// The collection of message attachments. | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,17 @@ | ||||||
namespace OrchardCore.Email; | ||||||
|
||||||
/// <summary> | ||||||
/// Represents a body for <see cref="MailMessage"/>. | ||||||
/// </summary> | ||||||
public class MailMessageBody | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add convenience methods for |
||||||
{ | ||||||
/// <summary> | ||||||
/// Gets or sets the body in plain text format. | ||||||
/// </summary> | ||||||
public string Text { get; set; } | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just think that in contrast to "HTML" it's clearer to have "plain text". It's also a term commonly used for this when talking about e-mail. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No problem we can rename it, but I usually "PlainText" in security :) |
||||||
|
||||||
/// <summary> | ||||||
/// Gets or sets the body in HTML format. | ||||||
/// </summary> | ||||||
public string Html { get; set; } | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For simplicity, I prefer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah but |
||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,10 @@ 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. | ||
|
||
|
||
The `MailMessage.Body` now returns `MailMessageBody` instead of `string` to support both plain text & HTML formats. | ||
Comment on lines
+15
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't needed in the 1.8 release notes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was planned for |
||
|
||
### TheAdmin Theme | ||
|
||
The `TheAdmin` theme was upgraded to Bootstrap 5.3.2. Here is a list of the breaking changes | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get this when opening a previously existing Email Task: