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

Incorporate Support For Templated Messages #12

Open
mitchelsellers opened this issue Apr 14, 2022 · 0 comments
Open

Incorporate Support For Templated Messages #12

mitchelsellers opened this issue Apr 14, 2022 · 0 comments

Comments

@mitchelsellers
Copy link
Contributor

This is different than the current implementation which is focused on the higher-level email. This is the actual CONTENT of the email.

Current usage outside of this project is

public interface IEmailMessageService
    {
        Task<string> BuildMessage(string messageTemplateName, List<KeyValuePair<string, string>> replacements);
    }

    public class EmailMessageService : IEmailMessageService
    {
        private readonly IWebHostEnvironment _environment;
        private readonly ITimeProvider _timeProvider;

        public EmailMessageService(IWebHostEnvironment environment, ITimeProvider timeProvider)
        {
            _environment = environment;
            _timeProvider = timeProvider;
        }

        public async Task<string> BuildMessage(string messageTemplateName,
            List<KeyValuePair<string, string>> replacements)
        {
            var templateBuilder = new StringBuilder(await File.ReadAllTextAsync(Path.Combine(_environment.WebRootPath,
                $"emailmessages/{messageTemplateName}.html")));

            foreach (var item in replacements)
                templateBuilder.Replace(item.Key, item.Value);
            return templateBuilder.ToString();
        }

    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant