Base solution for your next web application
Open Closed

Trying to use a new html email template in the asp zero project but it's not working. #6593


User avatar
0
system15 created

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)
  • User Avatar
    0
    ismcagdas created
    Support Team

    @system15

    Have you marked newTemplate.html as embedded resource ?

  • User Avatar
    0
    system15 created

    No i haven't. I'll give that a try.

  • User Avatar
    0
    system15 created

    Thanks @ismcagdas the email template works!

  • User Avatar
    0
    ashgadala created

    If any come likes to know where and how to mark embeded resource .

    https://aspnetboilerplate.com/Pages/Documents/Embedded-Resource-Files