-
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?
Conversation
@Mike4tel could you please try to send via |
@hishamco Html - OK |
All or Both make sense to me
This will revert the changes and let the body |
@sebastienros are we fine to add two bodies into the One option if we use |
Just pointing out that only stripping html will not let users format text nicely for plain text.. it is needed for good marketing. But I can see using stripped html version as another feature just to fight spam filters. |
Is it possible to merge this one? :) |
We forgot this one :) I will do a final review and then merge |
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.
@hishamco what is the problem that you are trying to solve? Why would we need All
as an enum value?
Maybe we should have an interface for the message like INotificationMessage
which we already have. Or something similar
public interface IEmailMessage
{
string Message { get; }
bool IsHtml { get; }
}
I don't think so, the issue was the email can be sent in both formats. In the past we already had |
This pull request has merge conflicts. Please resolve those before requesting a review. |
This pull request has merge conflicts. Please resolve those before requesting a review. |
# Conflicts: # src/OrchardCore.Modules/OrchardCore.Email/Controllers/AdminController.cs # src/OrchardCore.Modules/OrchardCore.Users/Controllers/EmailAuthenticatorController.cs # src/OrchardCore/OrchardCore.Email.Core/Services/SmtpService.cs
@MikeKry could you please do a last test, because we made a massive changes in the |
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Since GetProperty()
below uses this as the name by default, this will break existing Email Tasks, since they'll be empty. Add a migration that reads out the bodies of all Email Tasks, and depending on IsHtmlBody
, updates one of the fields with the old body value.
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.
The idea is to generate both bodies, so isHtmlBody
is not make sense here
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.
For the consumers of the old API, nothing will change. For the consumers of the new API, Obsolete
will tell that they shouldn't use this.
mode: { name: "liquid" }, | ||
}); | ||
|
||
$('select').onchange(function () { |
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.
activity.TextBody = new WorkflowExpression<string>(model.TextBody); | ||
activity.HtmlBody = new WorkflowExpression<string>(model.HtmlBody); |
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.
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.
/// <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; } |
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.
Since this is a published interface, keep the old properties with Obsolete
, and make them use the new Body
behind the scenes.
|
||
The `MailMessage.Body` now returns `MailMessageBody` instead of `string` to support both plain text & HTML formats. |
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.
This isn't needed in the 1.8 release notes.
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.
It was planned for 1.8
:)
/// <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 comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe IHtmlContent
instead to be better typed? With a convenience conversion method to/from string.
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.
For simplicity, I prefer string
instead, like other email messaging APIs
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.
Yeah but string
is really overused. IHtmlContent
is for when you want to store a string that's actually HTML.
@@ -14,7 +14,7 @@ public async Task SendEmail_WithToHeader() | |||
{ | |||
To = "info@oc.com", | |||
Subject = "Test", | |||
Body = "Test Message" | |||
Body = new MailMessageBody { Text = "Test Message" } |
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.
How about an implicit cast operator in MailMessageBody
from string
(fills Text
) and IHtmlContent
(fills Html
)? Then here you could write Body = "Test Message"
.
/// <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 comment
The reason will be displayed to describe this comment to others. Learn more.
public string Text { get; set; } | |
public string PlainText { get; set; } |
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 used Text
something similar to BodyBuilder.Text
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 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 comment
The reason will be displayed to describe this comment to others. Learn more.
No problem we can rename it, but I usually "PlainText" in security :)
Text = textBody?.Trim(), | ||
Html = htmlBody?.Trim() |
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.
Have you checked that actually both are sent if both are provided?
Co-authored-by: Zoltán Lehóczky <zoltan.lehoczky@lombiq.com>
This pull request has merge conflicts. Please resolve those before requesting a review. |
It seems that this pull request didn't really move for quite a while. Is this something you'd like to revisit any time soon or should we close? Please comment if you'd like to pick it up. |
I will revise this soon |
# Conflicts: # src/OrchardCore.Modules/OrchardCore.Users/Controllers/EmailAuthenticatorController.cs # src/OrchardCore.Modules/OrchardCore.Users/Extensions/ControllerExtensions.cs # src/OrchardCore.Modules/OrchardCore.Users/Workflows/Activities/RegisterUserTask.cs # src/OrchardCore/OrchardCore.Email.Abstractions/MailMessage.cs # src/OrchardCore/OrchardCore.Notifications.Core/Services/EmailNotificationProvider.cs # src/docs/releases/1.9.0.md # test/OrchardCore.Tests/Email/EmailTests.cs
@MikeKry could you please do one more test if you have time |
This pull request has merge conflicts. Please resolve those before requesting a review. |
This pull request has merge conflicts. Please resolve those before requesting a review. |
for instructions on how to resolve the merge conflicts due to #16572 please follow the step listed in this comment. |
It seems that this pull request didn't really move for quite a while. Is this something you'd like to revisit any time soon or should we close? Please comment if you'd like to pick it up. |
Seems I need to revisit this soon |
/cc @MikeKry