Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-23: Adding email template management and deferred email sending #57

Merged
merged 9 commits into from
Mar 13, 2022
Prev Previous commit
Next Next commit
Documenting email sending
  • Loading branch information
barthamark committed Feb 21, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit d558c1784c7c47a3551ab78ce37d9ca4fad57bdb
2 changes: 1 addition & 1 deletion Extensions/Emails/Services/EmailService.cs
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ public void SendEmailDeferred(EmailParameters parameters) =>
ShellScope.AddDeferredTask(async scope =>
{
var smtpService = scope.ServiceProvider.GetService<ISmtpService>();
var logger = scope.ServiceProvider.GetService<ILogger>();
var logger = scope.ServiceProvider.GetService<ILogger<EmailService>>();
sarahelsaig marked this conversation as resolved.
Show resolved Hide resolved
var result = await smtpService.SendAsync(new MailMessage
{
Sender = parameters.Sender,
11 changes: 0 additions & 11 deletions Extensions/Emails/Services/IEmailService.cs
Original file line number Diff line number Diff line change
@@ -13,15 +13,4 @@ public interface IEmailService
/// <param name="parameters">Parameters required for sending emails (e.g., recipients, subject, CC).</param>
void SendEmailDeferred(EmailParameters parameters);
}

public static class EmailServiceExtensions
{
public static void SendEmailDeferred(this IEmailService service, string to, string subject, string body) =>
service.SendEmailDeferred(new EmailParameters
{
To = new[] { to },
Subject = subject,
Body = body,
});
}
}
31 changes: 31 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -65,6 +65,37 @@ It displays an [accordion powered by Bootstrap](https://getbootstrap.com/docs/4.
prop-Children="IEnumerable<BootstrapAccordionItem>"></shape>
```

### Emails and Email Templates

#### Email Templates

Provides a shape-based email template rendering service. The email templates are represented by email template IDs that's also used to identify the corresponding shape using the following pattern: `EmailTemplate__{EmailTemplateID}`. E.g., for the `ContactUs` email template you need to create a shape with the `EmailTemplate__ContactUs` shape type.
sarahelsaig marked this conversation as resolved.
Show resolved Hide resolved

In the email template shapes use the `Layout__EmailTemplate` as the `ViewLayout` to wrap it with a simple HTML layout.

To extend the layout you can override the `EmailTemplate_LayoutInjections` shape and inject content to the specific zones provided by the layout to activate it in every email template. E.g.,

```html
<zone name="Footer">
Best,<br>
My Awesome Team
</zone>
```
To add inline styles include:
```html
<zone name="Head">
<style>
/* CSS code... */
</style>
</zone>
```

#### Deferred email sending

Use the `IEmailService.SendEmailDeferred()` for sending emails. It'll send emails after the shell scope has ended without blocking the request.



## Contributing and support

Bug reports, feature requests, comments, questions, code contributions, and love letters are warmly welcome, please do so via GitHub issues and pull requests. Please adhere to our [open-source guidelines](https://lombiq.com/open-source-guidelines) while doing so.