You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
.NET 8.0 Web API - UsingTemplateFromFile cannot find email template file #44
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