FluentEmail icon indicating copy to clipboard operation
FluentEmail copied to clipboard

Error when trying to get Razor email template on deployed server

Open pippinmole opened this issue 3 years ago • 3 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

pippinmole avatar Feb 23 '22 23:02 pippinmole

Instead of

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

try

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

dgreenway avatar Mar 14 '22 22:03 dgreenway

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?

johnwc avatar Aug 22 '22 02:08 johnwc

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

thaitm312 avatar Dec 07 '22 16:12 thaitm312