-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
72 lines (64 loc) · 2.04 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
using Templateless;
using Header = Templateless.Collection;
using Footer = Templateless.Collection;
using Templateless.Components;
namespace VerificationExample
{
class Program
{
static async Task Main(string[] args)
{
try
{
var apiKey = Environment.GetEnvironmentVariable("TEMPLATELESS_API_KEY");
if (string.IsNullOrEmpty(apiKey))
{
throw new InvalidOperationException("Set TEMPLATELESS_API_KEY to your Templateless API key");
}
var emailAddress = Environment.GetEnvironmentVariable("TEMPLATELESS_EMAIL_ADDRESS");
if (string.IsNullOrEmpty(emailAddress))
{
throw new InvalidOperationException("Set TEMPLATELESS_EMAIL_ADDRESS to your own email address");
}
var header = Header.Builder()
.Image("https://templateless.net/myco.webp", null, 100, null, "MyCo")
.Build();
var footer = Footer.Builder()
.Socials(new List<SocialItem>
{
new SocialItem(Service.Twitter, "MyCo"),
new SocialItem(Service.GitHub, "MyCo")
})
.Link("Unsubscribe", "https://example.com")
.Build();
var verifyEmailLink = "https://example.com/verify?token=ABC";
var content = Content.Builder()
.Theme(Theme.Simple)
.Header(header)
.Text("Hi there,")
.Text("Welcome to **MyCo**! We're excited to have you on board. Before we get started, we need to verify your email address.")
.Text("Please confirm your email by clicking the button below:")
.Button("Verify Email", verifyEmailLink)
.Text("Or use the link below:")
.Link(verifyEmailLink, verifyEmailLink)
.Footer(footer)
.Build();
var email = Email.Builder()
.To(new EmailAddress(emailAddress))
.Subject("Confirm your email")
.Content(content)
.Build();
var templateless = new TemplatelessClient(apiKey);
await templateless.SendEmailAsync(email);
}
catch (TemplatelessException ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}
catch (Exception ex)
{
Console.WriteLine($"An unexpected error occurred: {ex.Message}");
}
}
}
}