-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEmailTemplates.cs
More file actions
81 lines (76 loc) · 3.3 KB
/
EmailTemplates.cs
File metadata and controls
81 lines (76 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using VirtualFinland.UserAPI.Helpers.Configurations;
using static VirtualFinland.UserAPI.Helpers.Services.NotificationService;
namespace VirtualFinland.UserAPI.Helpers;
public class EmailTemplates
{
private readonly string _siteUrl;
public EmailTemplates(NotificationsConfig notificationsConfig)
{
_siteUrl = notificationsConfig.Email.SiteUrl;
}
public EmailTemplate GetEmailTemplateForPersonEmail(NotificationTemplate template)
{
return template switch
{
NotificationTemplate.AccountToBeDeletedFromInactivity => new EmailTemplate
{
Subject = "Your Access Finland account will be deleted from inactivity!",
HtmlBody = WrapEmailHtmlContentWithCoreTemplate("Your Access Finland account will be deleted from inactivity!", @$"
<h1>Your Access Finland account will be deleted from inactivity!</h1>
<p>Hi, you have not been active in Access Finland for a long time.</p>
<p>Unless you log in to Access Finland within a month, your account will be automatically deleted.</p>
<p>If you want to keep your account, please log in to Access Finland here:</p>
<p><a href=""{_siteUrl}"">{_siteUrl}</a></p>
"),
TextBody = "Your Access Finland account will be deleted from inactivity in 30 days!"
},
NotificationTemplate.AccountDeletedFromInactivity => new EmailTemplate
{
Subject = "Your Access Finland account was deleted from inactivity!",
HtmlBody = WrapEmailHtmlContentWithCoreTemplate("Your Access Finland account was deleted from inactivity!", @$"
<h1>Your Access Finland account was deleted from inactivity!</h1>
<p>Hello, a month ago we sent you an email about your Access Finland account being deleted from inactivity.</p>
<p>Since you did not log in to Access Finland within a month, your account was deleted.</p>
<p>If you want to continue using Access Finland service, please create a new account here:</p>
<p><a href=""{_siteUrl}"">{_siteUrl}</a></p>
"),
TextBody = "Your Access Finland account was deleted from inactivity!"
},
_ => throw new ArgumentException($"Email template {template} not found"),
};
}
private static string WrapEmailHtmlContentWithCoreTemplate(string title, string htmlBodyContent)
{
return @$"<!DOCTYPE html>
<html>
<head>
<meta charset=""utf-8"">
<meta name=""viewport"" content=""width=device-width, initial-scale=1.0"">
<title>{title}</title>
<style>
body {{
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
}}
</style>
</head>
<body>
<table role=""presentation"" cellspacing=""0"" cellpadding=""0"" border=""0"" align=""center"" width=""100%"" style=""max-width: 600px;"">
<tr>
<td>
{htmlBodyContent}
<hr />
<p>This message cannot be replied to.</p>
</td>
</tr>
</table>
</body>
</html>";
}
public record EmailTemplate
{
public string Subject { get; init; } = string.Empty;
public string HtmlBody { get; init; } = string.Empty;
public string TextBody { get; init; } = string.Empty;
}
}