Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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
You can do something like this https://github.com/TimGeyssens/MCFly/blob/master/MCFly/Core/EmailRenderer.cs
Then call it like https://github.com/TimGeyssens/MCFly/blob/master/MCFly/Controllers/MCFlyEntriesController.cs#L146
Hi Tim,
I guess this is exactly what I need, thank you very much :)
Cheers, Nadine
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.
Hey Nadine, if you debug what value is inside of viewFile
Here is the output
~/views/partials/emails/example/template
Maybe I have to search for "template.cshtml"?
yes, I have to pass the template with the fileextension "template.cshtml" Sorry for disturbing you :)
No problem, glad it's solved :)
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
get Email Template in Controller and pass modul-Variable
Hi,
I created a controller to send a confirmation Mail like this
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
You can do something like this https://github.com/TimGeyssens/MCFly/blob/master/MCFly/Core/EmailRenderer.cs
Then call it like https://github.com/TimGeyssens/MCFly/blob/master/MCFly/Controllers/MCFlyEntriesController.cs#L146
Hi Tim,
I guess this is exactly what I need, thank you very much :)
Cheers, Nadine
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
My view is in
And this is my constant view path to the templatesfolder
But i always get false if I check viewFile.Exists
Thank you for your advice.
Comment author was deleted
Hey Nadine, if you debug what value is inside of viewFile
Here is the output
Maybe I have to search for "template.cshtml"?
yes, I have to pass the template with the fileextension "template.cshtml" Sorry for disturbing you :)
Comment author was deleted
No problem, glad it's solved :)
is working on a reply...