-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
137 lines (131 loc) · 4.52 KB
/
Program.cs
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
using Mailgen;
using Mailgen.Templates;
using Mailgen.Templates.Models;
await TemplateGenerator.GenerateReceiptTemplate();
await TemplateGenerator.GenerateResetTemplate();
public class Item
{
public required string Name { get; set; }
public required string Description { get; set; }
public required string Price { get; set; }
}
public static class TemplateGenerator
{
public static async Task GenerateReceiptTemplate()
{
var product = new ProductModel
{
CopyrightLeft = "© 2024",
CopyrightRight = "All rights reserved.",
Link = "https://github.com/hsndmr",
Name = "Example Product"
};
var mailGenerator = new MailGenerator(product, new DefaultTemplate());
var body = new BodyModel<Item>
{
Title = "Hi John Appleseed,",
Intros =
[
"Your order has been processed successfully."
],
Tables = new List<TableModel<Item>>
{
new()
{
Columns =
[
new TableColumnModel<Item>
{
Header = "Item",
ValueSelector = item => item.Name,
Width = "20%"
},
new TableColumnModel<Item>
{
Header = "Description",
ValueSelector = item => item.Description
},
new TableColumnModel<Item>
{
Header = "Price",
ValueSelector = item => item.Price,
Width = "15%",
Align = "right"
}
],
Rows =
[
new Item
{
Name = "Node.js",
Description = "Event-driven I/O server-side JavaScript environment based on V8.",
Price = "$10.99"
},
new Item
{
Name = "Mailgen",
Description = "A .NET library for generating HTML emails.",
Price = "$1.99"
}
]
}
},
Actions =
[
new ActionModel
{
Instructions = "You can check the status of your order and more in your dashboard:",
Button = new ButtonModel
{
Color = "#22BC66",
Text = "Go to Dashboard",
Link = "https://github.com/hsndmr"
}
}
],
Outro =
[
"We thank you for your purchase."
],
Signature = "Yours truly"
};
var html = await mailGenerator.GenerateMail(body);
await File.WriteAllTextAsync(@"GeneratedTemplates/receipt.html", html);
}
public static async Task GenerateResetTemplate()
{
var product = new ProductModel
{
Link = "https://github.com/hsndmr",
Name = "Example Product"
};
var mailGenerator = new MailGenerator(product, new DefaultTemplate());
var body = new BodyModel<Item>
{
Title = "Hi John Appleseed,",
Intros =
[
"You have received this email because a password reset request for your account was received."
],
Actions =
[
new ActionModel
{
Instructions = "Click the button below to reset your password:",
Button = new ButtonModel
{
Color = "#DC4D2F",
Text = "Reset your password",
Link = "https://github.com/hsndmr"
}
}
],
Outro =
[
"If you did not request a password reset, no further action is required on your part."
]
};
var html = await mailGenerator.GenerateMail(body);
await File.WriteAllTextAsync(@"GeneratedTemplates/reset.html", html);
}
}