Skip to content

Commit

Permalink
emails
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-koshchei committed Feb 5, 2024
1 parent 50e983c commit a6a9962
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 36 deletions.
3 changes: 3 additions & 0 deletions docs/.obsidian/bookmarks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"items": []
}
4 changes: 2 additions & 2 deletions docs/.obsidian/workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@
},
"active": "ae86feaa91c640db",
"lastOpenFiles": [
"emails.md",
"index.md",
"getting-started.md",
"introduction.md",
"storage.md",
"emails.md"
"storage.md"
]
}
13 changes: 7 additions & 6 deletions docs/emails.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,12 @@ Console.WriteLine(sent switch

## Support

| | Link | Tested |
| -------- | ------------------------------------ | ------ |
| Resend | [resend.com](https://resend.com) | yes |
| SendGrid | [sendgrid.com](https://sendgrid.com) | yes |
| Brevo | [brevo.com](https://www.brevo.com/) | yes |
| | Link | Tested |
| -------- | -------------------------------------- | ------ |
| Resend | [resend.com](https://resend.com) | yes |
| SendGrid | [sendgrid.com](https://sendgrid.com) | yes |
| Brevo | [brevo.com](https://www.brevo.com) | yes |
| Mailjet | [mailjet.com](https://www.mailjet.com) | no |

## Inspiration

Expand Down Expand Up @@ -70,4 +71,4 @@ var email = Html(

var html = email.RenderHtml();
var text = email.RenderText();
```
```
28 changes: 27 additions & 1 deletion src/Unator/Emails.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,37 @@
using System.Collections.Immutable;
using System.Net;
using System.Net.Http.Headers;
using System.Text.Json;
using System.Text;
using System.Text.Json;

namespace Unator;

public static class EmailExample
{
public static async Task Run()
{
var email = new EmailSwitch(
new EmailService(new Resend("resend-api-token"), new DayLimiter(100)),
new EmailService(new Brevo("brevo-api-token"), new DayLimiter(300)),
new EmailService(new SendGrid("send-grid-api-token"), new DayLimiter(100))
);

var sent = await email.Send("[email protected]", "Roman Koshchei",
to: ["[email protected]"],
subject: "I own Flurium",
text: "Hi me from flurium account!",
html: "<h1>Hi me from flurium account!</h1>"
);

Console.WriteLine(sent switch
{
EmailStatus.Success => "Success",
EmailStatus.LimitReached => "Limits are reached",
_ => "Can't send an email"
});
}
}

public interface ILimiter
{
/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/Unator/Preruntime.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Reflection;
using System.Text;

namespace Unator;

Expand Down
28 changes: 2 additions & 26 deletions src/Web/Program.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,5 @@
using System.Net;
using Unator;
using static Unator.EnvInteresting;
using Unator;

//EnvExample.Run();

var email = new EmailSwitch(
new EmailService(new Resend("resend-api-token"), new DayLimiter(100)),
new EmailService(new Brevo("brevo-api-token"), new DayLimiter(300)),
new EmailService(new SendGrid("send-grid-api-token"), new DayLimiter(100))
);

// In future I plan create an email builder
// So it will be easy to create text and html versions at the same time
// For example Header("Hi me from flurium account!")

var sent = await email.Send("[email protected]", "Roman Koshchei",
to: ["[email protected]"],
subject: "I own Flurium",
text: "Hi me from flurium account!",
html: "<h1>Hi me from flurium account!</h1>"
);

Console.WriteLine(sent switch
{
EmailStatus.Success => "Success",
EmailStatus.LimitReached => "Limits are reached",
_ => "Can't send an email"
});
await EmailExample.Run();

0 comments on commit a6a9962

Please sign in to comment.