-
Notifications
You must be signed in to change notification settings - Fork 0
/
MailBuilder.cs
102 lines (89 loc) · 2.88 KB
/
MailBuilder.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
public class MailBuilder
{
protected StringBuilder Builder { get; set; }
public MailBuilder()
{
Builder = new StringBuilder();
}
public override string ToString()
{
return Builder.ToString();
}
}
public class HtmlMailBuilder : MailBuilder
{
public void AppendTable(Func<string> addRows, params string[] args)
{
Builder.AppendLine("<table>");
Builder.AppendLine("<thead>");
Builder.AppendLine("<tr>");
foreach (var arg in args)
{
Builder.AppendFormat("<th>{0}</th>", arg);
Builder.AppendLine();
}
Builder.AppendLine("</tr>");
Builder.AppendLine("</thead>");
Builder.AppendLine("<tbody>");
Builder.Append(addRows());
Builder.AppendLine("</tbody>");
Builder.AppendLine("</table>");
}
public void AppendTable(Action<HtmlMailBuilder> addRows, string classname = "", params string[] args)
{
Builder.AppendLine("<table class=\"" + classname + "\">");
Builder.AppendLine("<thead>");
Builder.AppendLine("<tr>");
foreach (var arg in args)
{
Builder.AppendFormat("<th>{0}</th>", arg);
Builder.AppendLine();
}
Builder.AppendLine("</tr>");
Builder.AppendLine("</thead>");
Builder.AppendLine("<tbody>");
addRows(this);
Builder.AppendLine("</tbody>");
Builder.AppendLine("</table>");
}
public void AppendRow(string classname = "", params string[] args)
{
Builder.AppendLine("<tr class=\"" + classname + "\">");
foreach (var arg in args)
{
Builder.AppendFormat("<td>{0}</td>", arg);
Builder.AppendLine();
}
Builder.AppendLine("</tr>");
}
public void AppendTitle(string content)
{
Builder.AppendLine(string.Format("<h1>{0}</h1>", content));
}
public void AppendTitle(int titleLevel, string content)
{
if (titleLevel < 1)
{
titleLevel = 1;
}
if (titleLevel > 6)
{
titleLevel = 6;
}
Builder.AppendLine(string.Format("<h{0}>{1}</h{0}>", titleLevel, content));
}
public void AppendBreak()
{
Builder.AppendLine("<br/>");
}
public void AppendHorizontalLine()
{
Builder.AppendLine("<hr/>");
}
public void AppendParagraph(string content)
{
Builder.AppendLine("<p>");
Builder.AppendLine(content);
Builder.AppendLine("</p>");
}
}