0

I have an issue with an mvc4 application in witch i would like to send a generated html page created with HTML + C#. The problem is that when i recieved the email i see my c# code like the exemple bellow: Recieved Email

But in the mail preview i can see the correct values like this: Mail Preview

So this is my EmailTemplate method:

<pre> public static async Task<string> EMailTemplate (string template) { var templateFilePath =HostingEnvironment.MapPath("~/Views/Home/") + template + ".cshtml"; StreamReader objstreamreaderfile = new StreamReader(templateFilePath); var body = await objstreamreaderfile.ReadToEndAsync(); objstreamreaderfile.Close(); return body; } </pre> 

Please if you have any idea how to convert my template to Html without inclouding my C# code.

Thanks,

2
  • where do you see the mail preview? By running the view in Visual Studio or any other editor? Commented Jun 20, 2016 at 11:34
  • 1
    You may be interested in nuget.org/packages/MvcMailer Commented Jun 20, 2016 at 12:26

1 Answer 1

2

Use Pure Html template (Not a cshtml view) with Inline CSS and Absolute image URIs for email body and fill it text templates. See the below image.

Demo Email Template

In the above image, field with ##...## are text templates.

Now read this HTML template as a string and replace ##...## fields by some dynamic information using the C# code (Actually any language code). You can use string.Replace() method to replace these fields by actual values. I have already used this method and it is working fine. I hope this will help you too.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.