I need to develop a C# program that reads an ASCII file that consists
of HTML code and send it out as an email to a mailing list.
The tough part for me is that the ASCII file must also support some
form of procedural logic that lets a user control the resulting
content.
The procedural code should be simple for a "super-user" to set up
(like VBScript or VB.NET).
In addition the user can select and embed pre-defined tags (wrapped
in, say, { and } characters) that my program will replace with values
from a database:
(e.g. {Country}, {Surname}, {Title}, etc.)
For example, using an ASP.NET metaphor, a user could set up a template
that looks like this:
<!---- start of template -->
<HTML>
<BODY>
Dear {Title} {Surname},<br><br>
<% if "{Country}" = "USA" then %>
<H1>Special offer to our USA subscribers only"</H1>
If you renew your subscription for only $100 , etc., etc.
<% else %>
<H1>Get fast international renewal deliveries today</H1>
If you renew your subscription for only $200 , etc., etc.
<% end if %>
</BODY>
</HTML>
<!---- end of template -->
The C# program (running as a Windows service) reads a list of names
and addresses from a database and sends an HTML email out to each
subscriber based on the template design. In this example, for each
name in the database, the {Country}, {Surname} and {Title} tags would
first be replaced with the person's live data by the C# program; the
"revised" template would be passed to the scripting engine which would
"interpret" it, "generate" the HTML content, and pass the "generated"
content back to the C# program, which would then send that content as
the body of an email; continuing the same procedure with the next
record, etc.
I don't want to rely on COM technology like Windows Scripting for
performance reasons.
1) Is there a .NET version of Windows Scripting ?
2) How is it invoked from C# (and passed the template) ?
3) How do I pass the generated HTML content that was created by the
scripting engine back to the C# program ? |
Request for Question Clarification by
mathtalk-ga
on
16 Apr 2003 18:45 PDT
Hi, wombatfish-ga:
If I understand your request, you want to write a Windows service in
C# that performs a "mail-merge" operation on an HTML template,
producing individualized HTML documents that you would then send as
email items.
Besides simple substitution on tags, you also want the ability to
evaluate "if...then" conditional logic using these tags. Such
capabilities are provided (for formatted text output) by Crystal
Reports and MS Word. You want to create a stand-alone executable to
do this with HTML output, which can in turn run as a service.
Have I missed anything? Is there something intrinsic about using the
scripting engine, other than the evaluation of the if...then
conditionals?
regards, mathtalk-ga
|
Clarification of Question by
wombatfish-ga
on
17 Apr 2003 01:20 PDT
A couple of years ago, I wrote a similar program in Delphi using the
Windows scripting engine. I found a freeware Delphi component on the
net that called the engine and retrieved the generated code. I was
hoping something similar was possible in C#...
The advantage of using the VBScript scripting engine was that you
could define variables and leverage functions in the template.
A good example was a template in which a "power-user" dynamically
built a URL from the data he was given.
e.g.
<%
Function CheckDigit(foobar1, foobar2, ED)
' using the three parameters, calculate and return a checkdigit to
prevent tampering with expiry date or other parameters..
End Function
Dim ED ' expiry date could change over time, so it's best kept in the
template
ED = "20030109"
%>
<HTML>
<BODY>
' foobar1 and foobar2 are price specific data
<a href=http:///www.foobar.com/orderform.asp?f1={foobar1}&f2={foobar2}&ED=<%=ED%>&checkdigit=<%=CheckDigit("{foobar1}",
"{foobar2}", ED)%>>Click here to order</a>
etc.
orderform.asp compared the checkdigit with the 3 params and blocked
tampered access...
I don't think that XML/XSLT is flexible enough, or quite so intuitive
for a user to grasp.
|