I have created a new html email template and I've put it in the same directory as the default.html file (Directory: myProject\src\myProject.Core\Emailing\EmailTemplates) with the ideas to be able to use a second template.
I have copied the following method and renamed it:
public string GetDefaultTemplate(int? tenantId) { using (var stream = typeof(EmailTemplateProvider).GetAssembly().GetManifestResourceStream("HomeDelivery.Emailing.EmailTemplates.default.html")) { var bytes = stream.GetAllBytes(); var template = Encoding.UTF8.GetString(bytes, 3, bytes.Length - 3); template = template.Replace("{THIS_YEAR}",DateTime.Now.Year.ToString()); return template.Replace("{EMAIL_LOGO_URL}", GetTenantLogoUrl(tenantId)); } }
New method that doesn't work when called:
public string GetBasicTemplate(int? tenantId) { using (var stream = typeof(EmailTemplateProvider).GetAssembly().GetManifestResourceStream("HomeDelivery.Emailing.EmailTemplates.newTemplate.html")) { var bytes = stream.GetAllBytes(); var template = Encoding.UTF8.GetString(bytes, 3, bytes.Length - 3); return template.Replace("{THIS_YEAR}", DateTime.Now.Year.ToString()); //return template.Replace("{EMAIL_LOGO_URL}", GetTenantLogoUrl(tenantId)); } }
When debugging and the line gets to the var bytes part I get an exception object reference not set to an instance of an object.
Any ideas how to resolve this so that I can alternate between templates without issues.
4 Answer(s)
-
0
@system15
Have you marked newTemplate.html as embedded resource ?
-
0
No i haven't. I'll give that a try.
-
0
Thanks @ismcagdas the email template works!
-
0
If any come likes to know where and how to mark embeded resource .
https://aspnetboilerplate.com/Pages/Documents/Embedded-Resource-Files