Skip to content

.NET 8.0 Web API - UsingTemplateFromFile cannot find email template file #44

Description

@alonstar

Hi everyone,

I am developing a .NET 8.0 Web API and trying to use UsingTemplateFromFile to parse an email template. However, the application throws an exception indicating that it cannot find the template file.

Here is my code setup:

builder.Services
        .AddRazorRenderer(Path.Combine(AppContext.BaseDirectory, "EmailTemplates"))
        .AddSmtpSender(new SmtpClient(smtp["Host"])
        {
            Port = int.Parse(smtp["Port"]),
            Credentials = new NetworkCredential(smtp["Username"], smtp["Password"]),
            EnableSsl = bool.Parse(smtp["EnableSsl"])
        });

This is not working.

var email = fluent
                .To("admin@gmail.com")
                .Subject("test")
                .UsingTemplateFromFile("WelcomeTemplate.cshtml", new Data());

This is working.

var email = fluent
                .To("admin@gmail.com")
                .Subject("test")
                .UsingTemplateFromFile("EmailTemplates/WelcomeTemplate.cshtml", new Data());

And the error is
System.IO.FileNotFoundException: Could not find file 'C:\Users\xxx\WebApi\WelcomeTemplate.cshtml'.

It looks like the default root is not working, did I do something wrong?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions