1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-26 12:55:17 +01:00

add back markdown mail service

This commit is contained in:
Kyle Spearrin 2017-10-30 21:36:00 -04:00
parent 05ece5dbd5
commit 377bf201d0
13 changed files with 298 additions and 0 deletions

View File

@ -8,6 +8,17 @@
<ItemGroup>
<EmbeddedResource Include="licensing.cer" />
<EmbeddedResource Include="MailTemplates\Markdown\ChangeEmail.md" />
<EmbeddedResource Include="MailTemplates\Markdown\ChangeEmailAlreadyExists.md" />
<EmbeddedResource Include="MailTemplates\Markdown\MasterPasswordHint.md" />
<EmbeddedResource Include="MailTemplates\Markdown\NoMasterPasswordHint.md" />
<EmbeddedResource Include="MailTemplates\Markdown\OrganizationUserAccepted.md" />
<EmbeddedResource Include="MailTemplates\Markdown\OrganizationUserConfirmed.md" />
<EmbeddedResource Include="MailTemplates\Markdown\OrganizationUserInvited.md" />
<EmbeddedResource Include="MailTemplates\Markdown\TwoFactorEmail.md" />
<EmbeddedResource Include="MailTemplates\Markdown\VerifyDelete.md" />
<EmbeddedResource Include="MailTemplates\Markdown\VerifyEmail.md" />
<EmbeddedResource Include="MailTemplates\Markdown\Welcome.md" />
<EmbeddedResource Include="MailTemplates\Razor\VerifyDelete.cshtml" />
<EmbeddedResource Include="MailTemplates\Razor\VerifyDelete.text.cshtml" />
<EmbeddedResource Include="MailTemplates\Razor\VerifyEmail.cshtml" />

View File

@ -0,0 +1 @@
To finalize changing your email address enter the following code in the pop-up window: {{token}}

View File

@ -0,0 +1,3 @@
A user ({{fromEmail}}) recently tried to change their account to use this email address ({{toEmail}}). An account already exists with this email ({{toEmail}}).
If you did not try to change an email address, you can safely ignore this email.

View File

@ -0,0 +1,7 @@
You (or someone) recently requested your master password hint.
Your hint is: "{{hint}}"
Login: <{{vaultUrl}}>
If you did not request your master password hint you can safely ignore this email.

View File

@ -0,0 +1,3 @@
You (or someone) recently requested your master password hint. Unfortunately, your account does not have a master password hint.
If you did not request your master password hint you can safely ignore this email.

View File

@ -0,0 +1,5 @@
This email is to notify you that {{userEmail}} has accepted your invitation to join {{organizationName}}.
To confirm this user, log into the bitwarden web vault, manage your organization "People" and confirm the user.
If you do not wish to confirm this user, you can also remove them from the organization on the same page.

View File

@ -0,0 +1,3 @@
This email is to notify you that you have been confirmed as a user of {{organizationName}}.
Any collections and logins being shared with you by this organization will now appear in your bitwarden vault.

View File

@ -0,0 +1,6 @@
You have been invited to join the {{organizationName}} organization. To accept this invite, click the
following link:
<{{url}}>
If you do not wish to join this organization, you can safely ignore this email.

View File

@ -0,0 +1,3 @@
Your two-step verification code is: {{token}}
Use this code to complete logging in with bitwarden.

View File

@ -0,0 +1,3 @@
Click the link below to delete your bitwarden account ({{email}}). If you did not request this email to delete your bitwarden account, you can safely ignore it.
<{{url}}>

View File

@ -0,0 +1,3 @@
Verify this email address for your bitwarden account by clicking the following link. If you did not request this email to verify a bitwarden account, you can safely ignore it.
<{{url}}>

View File

@ -0,0 +1,40 @@
Thank you for creating an account with bitwarden. You may now log in with your new account.
Did you know that bitwarden is free to sync with all of your devices? Download bitwarden today on:
Mobile
============
## iOS
<https://itunes.apple.com/us/app/bitwarden-free-password-manager/id1137397744?mt=8>
## Android
<https://play.google.com/store/apps/details?id=com.x8bit.bitwarden>
Desktop
============
## Chrome Extension
<https://chrome.google.com/webstore/detail/bitwarden-free-password-m/nngceckbapebfimnlniiiahkandclblb?utm_source=welcome_email&utm_medium=email>
## Firefox Extension
<https://addons.mozilla.org/firefox/addon/bitwarden-password-manager/>
## Opera Extension
<https://addons.opera.com/extensions/details/bitwarden-free-password-manager/?utm_source=welcome_email&utm_medium=email>
## Edge Extension
<https://www.microsoft.com/store/p/bitwarden-free-password-manager/9p6kxl0svnnl>
Web
============
You can also access your vault from any web-enabled device using our web vault at: <{{vaultUrl}}?utm_source=welcome_email&utm_medium=email>
------------
If you have any questions or problems you can email us from our website at:
<https://bitwarden.com/contact/?utm_source=welcome_email&utm_medium=email>
Thank you!
The bitwarden Team

View File

@ -0,0 +1,210 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Bit.Core.Models.Table;
using Bit.Core.Models.Mail;
using System.IO;
using System.Net;
using System.Reflection;
namespace Bit.Core.Services
{
public class MarkdownMailService : IMailService
{
private const string Namespace = "Bit.Core.MailTemplates.Markdown";
private readonly GlobalSettings _globalSettings;
private readonly IMailDeliveryService _mailDeliveryService;
public MarkdownMailService(
GlobalSettings globalSettings,
IMailDeliveryService mailDeliveryService)
{
_globalSettings = globalSettings;
_mailDeliveryService = mailDeliveryService;
}
public async Task SendVerifyEmailEmailAsync(string email, Guid userId, string token)
{
var model = new Dictionary<string, string>
{
["url"] = string.Format("{0}/verify-email?userId={1}&token={2}",
_globalSettings.BaseServiceUri.VaultWithHash, userId, WebUtility.UrlEncode(token))
};
var message = await CreateMessageAsync("Verify Your Email", email, "VerifyEmail", model);
message.MetaData.Add("SendGridBypassListManagement", true);
await _mailDeliveryService.SendEmailAsync(message);
}
public async Task SendVerifyDeleteEmailAsync(string email, Guid userId, string token)
{
var model = new Dictionary<string, string>
{
["url"] = string.Format("{0}/verify-recover-delete?userId={1}&token={2}&email={3}",
_globalSettings.BaseServiceUri.VaultWithHash,
userId,
WebUtility.UrlEncode(token),
WebUtility.UrlEncode(email)),
["email"] = WebUtility.HtmlEncode(email)
};
var message = await CreateMessageAsync("Delete Your Account", email, "VerifyDelete", model);
message.MetaData.Add("SendGridBypassListManagement", true);
await _mailDeliveryService.SendEmailAsync(message);
}
public async Task SendChangeEmailAlreadyExistsEmailAsync(string fromEmail, string toEmail)
{
var model = new Dictionary<string, string>
{
["fromEmail"] = WebUtility.HtmlEncode(fromEmail),
["toEmail"] = WebUtility.HtmlEncode(toEmail),
};
var message = await CreateMessageAsync("Your Email Change", toEmail, "ChangeEmailAlreadyExists", model);
message.MetaData.Add("SendGridBypassListManagement", true);
await _mailDeliveryService.SendEmailAsync(message);
}
public async Task SendChangeEmailEmailAsync(string newEmailAddress, string token)
{
var model = new Dictionary<string, string>
{
["token"] = token
};
var message = await CreateMessageAsync("Your Email Change", newEmailAddress, "ChangeEmail", model);
message.MetaData.Add("SendGridBypassListManagement", true);
await _mailDeliveryService.SendEmailAsync(message);
}
public async Task SendTwoFactorEmailAsync(string email, string token)
{
var model = new Dictionary<string, string>
{
["token"] = token
};
var message = await CreateMessageAsync("Your Two-step Login Verification Code", email, "TwoFactorEmail", model);
message.MetaData.Add("SendGridBypassListManagement", true);
await _mailDeliveryService.SendEmailAsync(message);
}
public async Task SendMasterPasswordHintEmailAsync(string email, string hint)
{
var model = new Dictionary<string, string>
{
["hint"] = WebUtility.HtmlEncode(hint),
["vaultUrl"] = _globalSettings.BaseServiceUri.VaultWithHash
};
var message = await CreateMessageAsync("Your Master Password Hint", email, "MasterPasswordHint", model);
message.MetaData.Add("SendGridBypassListManagement", true);
await _mailDeliveryService.SendEmailAsync(message);
}
public async Task SendNoMasterPasswordHintEmailAsync(string email)
{
var message = await CreateMessageAsync("Your Master Password Hint", email, "NoMasterPasswordHint", null);
message.MetaData.Add("SendGridBypassListManagement", true);
await _mailDeliveryService.SendEmailAsync(message);
}
public async Task SendOrganizationAcceptedEmailAsync(string organizationName, string userEmail,
IEnumerable<string> adminEmails)
{
var model = new Dictionary<string, string>
{
["userEmail"] = WebUtility.HtmlEncode(userEmail),
["organizationName"] = WebUtility.HtmlEncode(organizationName)
};
var message = await CreateMessageAsync($"User {userEmail} Has Accepted Invite", adminEmails,
"OrganizationUserAccepted", model);
message.MetaData.Add("SendGridBypassListManagement", true);
await _mailDeliveryService.SendEmailAsync(message);
}
public async Task SendOrganizationConfirmedEmailAsync(string organizationName, string email)
{
var model = new Dictionary<string, string>
{
["organizationName"] = WebUtility.HtmlEncode(organizationName)
};
var message = await CreateMessageAsync($"You Have Been Confirmed To {organizationName}", email,
"OrganizationUserConfirmed", model);
message.MetaData.Add("SendGridBypassListManagement", true);
await _mailDeliveryService.SendEmailAsync(message);
}
public async Task SendOrganizationInviteEmailAsync(string organizationName, OrganizationUser orgUser, string token)
{
var model = new Dictionary<string, string>
{
["organizationName"] = WebUtility.HtmlEncode(organizationName),
["url"] = string.Format("{0}/accept-organization?organizationId={1}&organizationUserId={2}" +
"&email={3}&organizationName={4}&token={5}",
_globalSettings.BaseServiceUri.VaultWithHash,
orgUser.OrganizationId,
orgUser.Id,
WebUtility.UrlEncode(orgUser.Email),
WebUtility.UrlEncode(organizationName),
WebUtility.UrlEncode(token))
};
var message = await CreateMessageAsync($"Join {organizationName}", orgUser.Email, "OrganizationUserInvited", model);
message.MetaData.Add("SendGridBypassListManagement", true);
await _mailDeliveryService.SendEmailAsync(message);
}
public async Task SendWelcomeEmailAsync(User user)
{
var model = new Dictionary<string, string>
{
["vaultUrl"] = _globalSettings.BaseServiceUri.VaultWithHash
};
var message = await CreateMessageAsync("Welcome", user.Email, "Welcome", model);
await _mailDeliveryService.SendEmailAsync(message);
}
private async Task<MailMessage> CreateMessageAsync(string subject, string toEmail, string fileName,
Dictionary<string, string> model)
{
return await CreateMessageAsync(subject, new List<string> { toEmail }, fileName, model);
}
private async Task<MailMessage> CreateMessageAsync(string subject, IEnumerable<string> toEmails, string fileName,
Dictionary<string, string> model)
{
var message = new MailMessage
{
ToEmails = toEmails,
Subject = subject,
MetaData = new Dictionary<string, object>()
};
var assembly = typeof(MarkdownMailService).GetTypeInfo().Assembly;
using(var s = assembly.GetManifestResourceStream($"{Namespace}.{fileName}.md"))
using(var sr = new StreamReader(s))
{
var markdown = await sr.ReadToEndAsync();
if(model != null)
{
foreach(var prop in model)
{
markdown = markdown.Replace($"{{{{{prop.Key}}}}}", prop.Value);
}
}
message.HtmlContent = CommonMark.CommonMarkConverter.Convert(markdown);
message.TextContent = markdown;
}
return message;
}
}
}