mirror of
https://github.com/bitwarden/server
synced 2026-01-05 18:13:31 +00:00
subscription renewal reminder emails
This commit is contained in:
@@ -179,6 +179,20 @@ namespace Bit.Core.Services
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SendInvoiceUpcomingAsync(string email, decimal amount, DateTime dueDate,
|
||||
List<string> items, bool mentionInvoices)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _primaryMailService.SendInvoiceUpcomingAsync(email, amount, dueDate, items, mentionInvoices);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
LogError(e);
|
||||
await _backupMailService.SendInvoiceUpcomingAsync(email, amount, dueDate, items, mentionInvoices);
|
||||
}
|
||||
}
|
||||
|
||||
private void LogError(Exception e)
|
||||
{
|
||||
_logger.LogError(e, "Error sending mail with primary service, using backup.");
|
||||
|
||||
@@ -190,6 +190,22 @@ namespace Bit.Core.Services
|
||||
await _mailDeliveryService.SendEmailAsync(message);
|
||||
}
|
||||
|
||||
public async Task SendInvoiceUpcomingAsync(string email, decimal amount, DateTime dueDate,
|
||||
List<string> items, bool mentionInvoices)
|
||||
{
|
||||
var model = new Dictionary<string, string>
|
||||
{
|
||||
["vaultUrl"] = _globalSettings.BaseServiceUri.VaultWithHash,
|
||||
["dueDate"] = dueDate.ToString("MMM dd, yyyy"),
|
||||
["amountDue"] = amount.ToString("C")
|
||||
};
|
||||
|
||||
var message = await CreateMessageAsync("Your Subscription Will Renew Soon", email,
|
||||
"InvoiceUpcoming", model);
|
||||
message.BccEmails = new List<string> { "kyle@bitwarden.com" };
|
||||
await _mailDeliveryService.SendEmailAsync(message);
|
||||
}
|
||||
|
||||
private async Task<MailMessage> CreateMessageAsync(string subject, string toEmail, string fileName,
|
||||
Dictionary<string, string> model)
|
||||
{
|
||||
|
||||
@@ -223,6 +223,26 @@ namespace Bit.Core.Services
|
||||
await _mailDeliveryService.SendEmailAsync(message);
|
||||
}
|
||||
|
||||
public async Task SendInvoiceUpcomingAsync(string email, decimal amount, DateTime dueDate,
|
||||
List<string> items, bool mentionInvoices)
|
||||
{
|
||||
var message = CreateDefaultMessage("Your Subscription Will Renew Soon", email);
|
||||
message.BccEmails = new List<string> { "kyle@bitwarden.com" };
|
||||
|
||||
var model = new InvoiceUpcomingViewModel
|
||||
{
|
||||
WebVaultUrl = _globalSettings.BaseServiceUri.VaultWithHash,
|
||||
SiteName = _globalSettings.SiteName,
|
||||
AmountDue = amount,
|
||||
DueDate = dueDate,
|
||||
Items = items,
|
||||
MentionInvoices = mentionInvoices
|
||||
};
|
||||
message.HtmlContent = await _engine.CompileRenderAsync("InvoiceUpcoming", model);
|
||||
message.TextContent = await _engine.CompileRenderAsync("InvoiceUpcoming.text", model);
|
||||
await _mailDeliveryService.SendEmailAsync(message);
|
||||
}
|
||||
|
||||
private MailMessage CreateDefaultMessage(string subject, string toEmail)
|
||||
{
|
||||
return CreateDefaultMessage(subject, new List<string> { toEmail });
|
||||
|
||||
@@ -39,6 +39,10 @@ namespace Bit.Core.Services
|
||||
sendGridMessage.SetClickTracking(true, false);
|
||||
sendGridMessage.SetOpenTracking(true, null);
|
||||
sendGridMessage.AddTos(message.ToEmails.Select(e => new EmailAddress(e)).ToList());
|
||||
if(message.BccEmails?.Any() ?? false)
|
||||
{
|
||||
sendGridMessage.AddBccs(message.BccEmails.Select(e => new EmailAddress(e)).ToList());
|
||||
}
|
||||
|
||||
if(message.MetaData?.ContainsKey("SendGridTemplateId") ?? false)
|
||||
{
|
||||
|
||||
@@ -50,6 +50,14 @@ namespace Bit.Core.Services
|
||||
smtpMessage.To.Add(new MailAddress(address));
|
||||
}
|
||||
|
||||
if(message.BccEmails != null)
|
||||
{
|
||||
foreach(var address in message.BccEmails)
|
||||
{
|
||||
smtpMessage.Bcc.Add(new MailAddress(address));
|
||||
}
|
||||
}
|
||||
|
||||
if(string.IsNullOrWhiteSpace(message.TextContent))
|
||||
{
|
||||
smtpMessage.IsBodyHtml = true;
|
||||
|
||||
Reference in New Issue
Block a user