using System.Text.Encodings.Web;
using BTCPayServer.Services.Mails;
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)
{
string button = $"{BUTTON_HTML}".Replace("{button_description}", actionName, System.StringComparison.InvariantCulture);
button = button.Replace("{button_link}", actionLink, System.StringComparison.InvariantCulture);
return button;
}
public static void SendEmailConfirmation(this IEmailSender emailSender, string email, string link)
{
emailSender.SendEmail(email, "Confirm your email",
$"Please confirm your account by clicking this link: link");
}
public static void SendSetPasswordConfirmation(this IEmailSender emailSender, string email, string link, bool newPassword)
{
var subject = $"{(newPassword ? "Set" : "Update")} Password";
var body = $"A request has been made to {(newPassword ? "set" : "update")} your BTCPay Server password. Please confirm your password by clicking below.
{CallToAction(subject, HtmlEncoder.Default.Encode(link))}";
emailSender.SendEmail(email,
subject,
$"{HEADER_HTML}{body}");
}
}
}