using System.Text.Encodings.Web; using BTCPayServer.Services.Mails; using MimeKit; namespace BTCPayServer.Services { public static class EmailSenderExtensions { private static string BODY_STYLE = "font-family: Open Sans, Helvetica Neue,Arial,sans-serif; font-color: #292929;"; private static string HEADER_HTML = "

BTCPay Server


"; private static string BUTTON_HTML = "{button_description}"; private static string CallToAction(string actionName, string actionLink) { var button = $"{BUTTON_HTML}".Replace("{button_description}", actionName, System.StringComparison.InvariantCulture); return button.Replace("{button_link}", HtmlEncoder.Default.Encode(actionLink), System.StringComparison.InvariantCulture); } private static string CreateEmailBody(string body) { return $"{HEADER_HTML}{body}"; } public static void SendEmailConfirmation(this IEmailSender emailSender, MailboxAddress address, string link) { emailSender.SendEmail(address, "Confirm your email", CreateEmailBody( $"Please confirm your account.

{CallToAction("Confirm Email", link)}")); } public static void SendApprovalConfirmation(this IEmailSender emailSender, MailboxAddress address, string link) { emailSender.SendEmail(address, "Your account has been approved", CreateEmailBody( $"Your account has been approved and you can now login here.")); } public static void SendResetPassword(this IEmailSender emailSender, MailboxAddress address, string link) { emailSender.SendEmail(address, "Update Password", CreateEmailBody( $"A request has been made to reset your BTCPay Server password. Please set your password by clicking below.

{CallToAction("Update Password", link)}")); } public static void SendInvitation(this IEmailSender emailSender, MailboxAddress address, string link) { emailSender.SendEmail(address, "Invitation", CreateEmailBody( $"Please complete your account setup by clicking this link.")); } public static void SendNewUserInfo(this IEmailSender emailSender, MailboxAddress address, string newUserInfo, string link) { emailSender.SendEmail(address, newUserInfo, CreateEmailBody( $"{newUserInfo}. You can verify and approve the account here: User details")); } public static void SendUserInviteAcceptedInfo(this IEmailSender emailSender, MailboxAddress address, string userInfo, string link) { emailSender.SendEmail(address, userInfo, CreateEmailBody( $"{userInfo}. You can view the store users here: Store users")); } } }