From 159d4cc32de46e7b74640ba5b003a875129d6f7b Mon Sep 17 00:00:00 2001 From: Hinton Date: Wed, 4 Jun 2025 17:39:55 +0200 Subject: [PATCH] WIP --- .../Registration/VerifyEmail/VerifyEmail.cs | 9 ++++++ .../VerifyEmail/VerifyEmail.html.hbs | 24 +++++++++++++++ .../VerifyEmail/VerifyEmail.txt.hbs | 8 +++++ .../Layouts/TitleContactUs.html.hbs | 5 ++-- src/Core/Platform/Services/IMailModel.cs | 30 +++++++++++++++++++ src/Core/Platform/Services/IMailer.cs | 23 ++++++++++++++ src/Core/Platform/Services/Mailer.cs | 11 +++++++ 7 files changed, 108 insertions(+), 2 deletions(-) create mode 100644 src/Core/Auth/UserFeatures/Registration/VerifyEmail/VerifyEmail.cs create mode 100644 src/Core/Auth/UserFeatures/Registration/VerifyEmail/VerifyEmail.html.hbs create mode 100644 src/Core/Auth/UserFeatures/Registration/VerifyEmail/VerifyEmail.txt.hbs create mode 100644 src/Core/Platform/Services/IMailModel.cs create mode 100644 src/Core/Platform/Services/IMailer.cs create mode 100644 src/Core/Platform/Services/Mailer.cs diff --git a/src/Core/Auth/UserFeatures/Registration/VerifyEmail/VerifyEmail.cs b/src/Core/Auth/UserFeatures/Registration/VerifyEmail/VerifyEmail.cs new file mode 100644 index 0000000000..81e5e69aeb --- /dev/null +++ b/src/Core/Auth/UserFeatures/Registration/VerifyEmail/VerifyEmail.cs @@ -0,0 +1,9 @@ +using Bit.Core.Platform.Services; + +namespace Bit.Core.Auth.UserFeatures.Registration.VerifyEmail; + +public class VerifyEmail(string url) : BaseMailModel2 +{ + public override string Subject { get; set; } = "Verify Your Email"; + public string Url { get; } = url; +} diff --git a/src/Core/Auth/UserFeatures/Registration/VerifyEmail/VerifyEmail.html.hbs b/src/Core/Auth/UserFeatures/Registration/VerifyEmail/VerifyEmail.html.hbs new file mode 100644 index 0000000000..f9290a46fb --- /dev/null +++ b/src/Core/Auth/UserFeatures/Registration/VerifyEmail/VerifyEmail.html.hbs @@ -0,0 +1,24 @@ +{{#>FullHtmlLayout}} + + + + + + + + + + +
+ Verify this email address for your Bitwarden account by clicking the link below. +
+ If you did not request to verify a Bitwarden account, you can safely ignore this email. +
+
+
+ + Verify Email Address Now + +
+
+{{/FullHtmlLayout}} diff --git a/src/Core/Auth/UserFeatures/Registration/VerifyEmail/VerifyEmail.txt.hbs b/src/Core/Auth/UserFeatures/Registration/VerifyEmail/VerifyEmail.txt.hbs new file mode 100644 index 0000000000..42faf94eab --- /dev/null +++ b/src/Core/Auth/UserFeatures/Registration/VerifyEmail/VerifyEmail.txt.hbs @@ -0,0 +1,8 @@ +{{#>BasicTextLayout}} + Verify this email address for your Bitwarden account by clicking the link below. + + If you did not request to verify a Bitwarden account, you can safely ignore this email. + + {{{Url}}} + +{{/BasicTextLayout}} diff --git a/src/Core/MailTemplates/Handlebars/Layouts/TitleContactUs.html.hbs b/src/Core/MailTemplates/Handlebars/Layouts/TitleContactUs.html.hbs index ed0d7cd9af..1167d9bce7 100644 --- a/src/Core/MailTemplates/Handlebars/Layouts/TitleContactUs.html.hbs +++ b/src/Core/MailTemplates/Handlebars/Layouts/TitleContactUs.html.hbs @@ -1,4 +1,5 @@ -{{#>FullUpdatedHtmlLayout}} + +{{#>FullUpdatedHtmlLayout}}
@@ -41,4 +42,4 @@
-{{/FullUpdatedHtmlLayout}} \ No newline at end of file +{{/FullUpdatedHtmlLayout}} diff --git a/src/Core/Platform/Services/IMailModel.cs b/src/Core/Platform/Services/IMailModel.cs new file mode 100644 index 0000000000..196ca2091b --- /dev/null +++ b/src/Core/Platform/Services/IMailModel.cs @@ -0,0 +1,30 @@ +namespace Bit.Core.Platform.Services; + +#nullable enable + +/// +/// IMail describes a view model for emails. Any propery in the view model are available for usage +/// in the email templates. +/// +/// Each Mail consists of two body parts: a text part and an HTML part and the filename must be +/// relative to the viewmodel and match the following pattern: +/// - `{ClassName}.html.hbs` for the HTML part +/// - `{ClassName}.txt.hbs` for the text part +/// +public abstract class BaseMailModel2 +{ + /// + /// The subject of the email. + /// + public abstract string Subject { get; set; } + + /// + /// An optional category for processing at the upstream email delivery service. + /// + public string? Category { get; set; } + + /// + /// Current year. + /// + public string CurrentYear => DateTime.UtcNow.Year.ToString(); +} diff --git a/src/Core/Platform/Services/IMailer.cs b/src/Core/Platform/Services/IMailer.cs new file mode 100644 index 0000000000..c14d9d6f56 --- /dev/null +++ b/src/Core/Platform/Services/IMailer.cs @@ -0,0 +1,23 @@ +namespace Bit.Core.Platform.Services; + +#nullable enable + +/// +/// +/// +public interface IMailer +{ + /// + /// Sends an email message to the specified recipient. + /// + /// + /// Recipient email + public void SendEmail(BaseMailModel2 message, string recipient); + + /// + /// Sends multiple emails message to the specified recipients. + /// + /// + /// Recipient emails + public void SendEmails(BaseMailModel2 message, string[] recipients); +} diff --git a/src/Core/Platform/Services/Mailer.cs b/src/Core/Platform/Services/Mailer.cs new file mode 100644 index 0000000000..8167fc1fe6 --- /dev/null +++ b/src/Core/Platform/Services/Mailer.cs @@ -0,0 +1,11 @@ +namespace Bit.Core.Platform.Services; + +#nullable enable + + +public class Mailer : IMailer +{ + public void SendEmail(BaseMailModel2 message, string recipient) => throw new NotImplementedException(); + + public void SendEmails(BaseMailModel2 message, string[] recipients) => throw new NotImplementedException(); +}