2017-09-13 15:47:34 +09:00
using System.Text.Encodings.Web ;
2017-09-15 16:06:57 +09:00
using BTCPayServer.Services.Mails ;
2022-06-22 05:05:32 +02:00
using MimeKit ;
2017-09-13 15:47:34 +09:00
namespace BTCPayServer.Services
{
public static class EmailSenderExtensions
{
2021-01-27 09:42:47 +02:00
private static string BODY_STYLE = "font-family: Open Sans, Helvetica Neue,Arial,sans-serif; font-color: #292929;" ;
private static string HEADER_HTML = "<h1 style='font-size:1.2rem'>BTCPay Server</h1><br/>" ;
private static string BUTTON_HTML = "<a href='{button_link}' type='submit' style='min-width: 2em;min-height: 20px;text-decoration-line: none;cursor: pointer;display: inline-block;font-weight: 400;color: #fff;text-align: center;vertical-align: middle;user-select: none;background-color: #51b13e;border-color: #51b13e;border: 1px solid transparent;padding: 0.375rem 0.75rem;font-size: 1rem;line-height: 1.5;border-radius: 0.25rem;transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;'>{button_description}</a>" ;
private static string CallToAction ( string actionName , string actionLink )
{
string button = $"{BUTTON_HTML}" . Replace ( "{button_description}" , actionName , System . StringComparison . InvariantCulture ) ;
2021-12-31 16:59:02 +09:00
button = button . Replace ( "{button_link}" , actionLink , System . StringComparison . InvariantCulture ) ;
2021-01-27 09:42:47 +02:00
return button ;
}
2022-06-22 05:05:32 +02:00
public static void SendEmailConfirmation ( this IEmailSender emailSender , MailboxAddress address , string link )
2017-09-13 15:47:34 +09:00
{
2024-02-28 12:43:18 +01:00
emailSender . SendEmail ( address , "BTCPay Server: Confirm your email" ,
$"Please confirm your account by clicking <a href='{HtmlEncoder.Default.Encode(link)}'>this link</a>." ) ;
2017-09-13 15:47:34 +09:00
}
2021-12-31 16:59:02 +09:00
2024-01-31 06:45:54 +01:00
public static void SendApprovalConfirmation ( this IEmailSender emailSender , MailboxAddress address , string link )
{
2024-02-28 12:43:18 +01:00
emailSender . SendEmail ( address , "BTCPay Server: Your account has been approved" ,
$"Your account has been approved and you can now <a href='{HtmlEncoder.Default.Encode(link)}'>login here</a>." ) ;
2024-01-31 06:45:54 +01:00
}
2024-02-28 12:43:18 +01:00
public static void SendResetPassword ( this IEmailSender emailSender , MailboxAddress address , string link )
2020-09-05 12:16:48 +02:00
{
2024-02-28 12:43:18 +01:00
var body = $"A request has been made to reset your BTCPay Server password. Please set your password by clicking below.<br/><br/>{CallToAction(" Update Password ", HtmlEncoder.Default.Encode(link))}" ;
emailSender . SendEmail ( address , "BTCPay Server: Update Password" , $"<html><body style='{BODY_STYLE}'>{HEADER_HTML}{body}</body></html>" ) ;
}
public static void SendInvitation ( this IEmailSender emailSender , MailboxAddress address , string link )
{
emailSender . SendEmail ( address , "BTCPay Server: Invitation" ,
$"Please complete your account setup by clicking <a href='{HtmlEncoder.Default.Encode(link)}'>this link</a>." ) ;
}
public static void SendNewUserInfo ( this IEmailSender emailSender , MailboxAddress address , string newUserInfo , string link )
{
emailSender . SendEmail ( address , $"BTCPay Server: {newUserInfo}" ,
$"{newUserInfo}. You can verify and approve the account here: <a href='{HtmlEncoder.Default.Encode(link)}'>User details</a>" ) ;
2020-09-05 12:16:48 +02:00
}
2017-09-13 15:47:34 +09:00
}
}