lukencode / FluentEmail

All in one email sender for .NET. Supports popular senders (SendGrid, MailGun, etc) and Razor templates.

Home Page:https://lukelowrey.com/dotnet-email-guide-2021/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when trying to get Razor email template on deployed server

pippinmole opened this issue · comments

image

I initialize the Razor renderer here, setting the template root folder, which works fine on my local machine, but once I deploy it to Heroku (Linux) it throws this exception:
image

They are running the same code, but different results? Very confusing to me.

This is the code that is sending the email:
image

I do see that I am overlapping /Email Templates - In Startup.cs I have $"{Directory.GetCurrentDirectory()}/Email Templates") and then inside the SendResetPasswordAsync method, UsingTemplateFromFile("Email Templates/ResetPassword.cshtml", but it is confusing to me how this works fine on my desktop, but not in a production environment?

I could be doing something entirely wrong, or a bug

Instead of

.AddRazorRenderer($"{Directory.GetCurrentDirectory()}/Email Templates")

try

.AddRazorRender(options =>  options.FileProvider = new PhysicalFileProvider(Path.Combine(contentRootPath, "Email Templates")))

That still does not fix it, as the UsingTemplateFromFile method is not correctly calling the renderer with the filename. It is trying to read the contents of the file first, then call the parse method of the renderer.

https://github.com/lukencode/FluentEmail/blob/master/src/FluentEmail.Core/Email.cs#L343

@lukencode Think we can get these little things fixed and deployed with new version?

This issue still not resolved on December. It seems that the FileProvider in RenderOptions is not used at all.