Bob
Bob

Reputation: 47

Creating a dynamic HTML email pulled from SQL Server database

I'm trying to put together a newsletter that links to articles on a website through Visual Studio windows forms. I can successfully pull out the article links which are stored in a SQL Server database.

My problem is how to handle the rest of the HTML email, for example how can I store the rest of the HTML body, style tags etc without making my code a complete mess, I've tried breaking it up into several parts stored in several string variables but then realised

  1. what a mess it made my code and
  2. that I had no way to handle the double quotes within the email content

Basically I just need some advice on how to handle the HTML body content of the email to then add in my articles, which are pulled from a SQL Server database, into the HTML

Upvotes: 0

Views: 492

Answers (1)

Alex K.
Alex K.

Reputation: 175936

Keep the static email text outside of your application; create a template file (or field in the db) using {CONTENT} / {TITLE} style placeholder strings, load the file and replace("{CONTENT}", db_value) for all the values you need.

There is also the built in MailDefinition class from System.Web which does the same.

Upvotes: 1

Related Questions