-1

In .Net Core, we can send HTML email using

bodyBuilder.HtmlBody = @"<div> anything </div>"

It's there a way to load the <div> content from external .html file, something like

bodyBuilder.HtmlBody = (load msg.html)
Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203
  • Please stop forcing tags into the questions! Read http://stackoverflow.com/help/tagging on how to correctly use tags – Tseng Nov 08 '16 at 18:38
  • @Tseng did not get you, what wrong in the tags! And why you down vote the question,? – Hasan A Yousef Nov 08 '16 at 18:50
  • Said it above, don't force the tags into question **TITLE**. Just put them in the tag section. The title should roughly describe your problem. From your reputation you are long enough on StackOverflow to have had the opportunity to read the help center articles and know how to ask a question. Also the last dozen of your questions all had multiple tags forced into the title. This is not a form, its **not necessary** to put tags into the title. I just had to go through a dozen of your recent question to remove the tags, time we can't use for answering other questions – Tseng Nov 08 '16 at 18:57
  • @Tseng your point about the tag in the title is clear now, but did not get why you down voted the question? – Hasan A Yousef Nov 08 '16 at 19:02

1 Answers1

1

Just read the contents of the file like it is a regular text file. The simplest way to do that by calling File.ReadAllText method:

string htmlFilePath = "msg.html";
bodyBuilder.HtmlBody = File.ReadAllText(htmlFilePath);

Don't forget about namespace:

using System.IO;

I believe the required NuGet package is System.IO.

Deilan
  • 4,740
  • 3
  • 39
  • 52
  • Thanks, but if I publish the file as SCD, it is not seeing the "msg.file" and give me an error `file not found`? – Hasan A Yousef Nov 15 '16 at 15:42
  • @HasanAYousef, Provide the contents of `project.json` here. – Deilan Nov 15 '16 at 19:46
  • kindly look at this, a I tried to make it a different question instead adding to the existing one: http://stackoverflow.com/questions/40612533/accessing-static-files-in-scd/40625065#40625065 – Hasan A Yousef Nov 16 '16 at 06:02
  • @HasanAYousef, you target wrong framework. You should target `netcoreapp1.0` instead of `netstandard1.6`. – Deilan Nov 16 '16 at 09:02
  • @Deialn it is not wrong, it is the recomended one from MS to have minimal footprint. – Hasan A Yousef Nov 16 '16 at 09:20
  • 1
    @HasanAYousef, `netstandard` is just for **class libraries**, not for applications. `netcoreapp` is for applications. Learn more [here](https://learn.microsoft.com/en-us/dotnet/articles/standard/library). – Deilan Nov 16 '16 at 09:23