• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 817
  • Last Modified:

System.Net.Mail.MailMessage: Insert Body from File

The body of my email is fairly complicated HTML.  instead of trying to code it all in the code behind file, I'd like to code it in an html file (possibly called BodyOfMessage.htm or BodyOfMessage.txt) and then read/insert the file in as the body of the email.

How do i do this?
0
davidcahan
Asked:
davidcahan
  • 3
  • 2
1 Solution
 
aibusinesssolutionsCommented:
That's pretty simple, you just open the HTML file as a string, and then replace the variables.

Dim emailFile As String = IO.File.ReadAllText(Server.MapPath("~/path-to-file/BodyOfMessage.htm"))
emailFile.Replace("[Variable]", variable)

EmailMsg.Body = emailFile
0
 
davidcahanAuthor Commented:
yea...knew it was gonna wind up being simple.  thanks
0
 
davidcahanAuthor Commented:
actually...what is that part where you replace the variables?  what variables are you replacing
0
 
aibusinesssolutionsCommented:
In your HTML file, you could have something like this

<body>
<p>Dear [Fullname],</p>
<p>Thank you for ordering [productName].</p>
</body>

Then you would replace them like template fields.
emailFile.Replace("[FullName]", obj.FullName)
emailFile.Replace("[productName]", obj.ProductName)
0
 
davidcahanAuthor Commented:
ahhh...ok. that's what i thought but i wasn't sure.  thanks again
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now