Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nadine Fisch 159 posts 429 karma points
    Jun 04, 2018 @ 09:21
    Nadine Fisch
    0

    get Email Template in Controller and pass modul-Variable

    Hi,

    I created a controller to send a confirmation Mail like this

     private void SendConfirmationEmail(Modul modul){
            MailMessage message = new MailMessage(modul.Email,"[email protected]");
            message.Subject = "Subject example";
            message.Body = getEmailTemplate(modul);
            SmtpClient client = new SmtpClient("127.0.0.1", 25);
            client.Send(message);
    
        }
    

    And I want to create a function "getEmailTemplate". Where can I store the Email-Templates? Can I use the Views-Folder for it? And how can I pass and read the variables of modul?

    Thank you in advance,

    Nadine

  • Comment author was deleted

    Jun 04, 2018 @ 09:35
  • Nadine Fisch 159 posts 429 karma points
    Jun 04, 2018 @ 09:43
    Nadine Fisch
    0

    Hi Tim,

    I guess this is exactly what I need, thank you very much :)

    Cheers, Nadine

  • Nadine Fisch 159 posts 429 karma points
    Jun 14, 2018 @ 11:49
    Nadine Fisch
    0

    I try to reuse your the EmailRenderer-Class, but I fail on using the correct path for the view-folder. Can you help me please?

    In my case, the EmailRenderer-class is in

    App_code\Controllers\Core\EmailRenderer.cs
    

    My view is in

    Views\Partials\emails\example\template.cshtml
    

    And this is my constant view path to the templatesfolder

    private const string EmailViewPath = "~/views/partials/emails/example/";
    

    But i always get false if I check viewFile.Exists

    var viewPath = Path.Combine(EmailViewPath, viewName);
    var viewFile = new FileInfo(HostingEnvironment.MapPath(viewPath));
        if(viewFile.Exists == false) {
            return viewPath;
        }
    

    Thank you for your advice.

  • Comment author was deleted

    Jun 14, 2018 @ 12:09

    Hey Nadine, if you debug what value is inside of viewFile

  • Nadine Fisch 159 posts 429 karma points
    Jun 14, 2018 @ 12:10
    Nadine Fisch
    0

    Here is the output

       ~/views/partials/emails/example/template
    

    Maybe I have to search for "template.cshtml"?

  • Nadine Fisch 159 posts 429 karma points
    Jun 14, 2018 @ 12:20
    Nadine Fisch
    0

    yes, I have to pass the template with the fileextension "template.cshtml" Sorry for disturbing you :)

  • Comment author was deleted

    Jun 14, 2018 @ 12:28

    No problem, glad it's solved :)

Please Sign in or register to post replies

Write your reply to:

Draft