Best Way Html Formatted Email

  • Thread starter Thread starter Leon
  • Start date Start date
L

Leon

What's the best way to send html formatted email (newsletter style)?
In Code or In Web Config files? I'm thinking in code using StringWriter and
HtmlTextWriter?
 
I'm not sure what you mean with "in Web config files" Typically you'd build
a string (stringbuilder is a smart idea) ala:

Dim sb As New StringBuilder
sb.append(...)

Dim message As New Mail.MailMessage
message.BodyFormat = Mail.MailFormat.Html
message.Body = sb.ToString()


It might also be a good idea to store your messages in an XML file with
placeholders and use a strongly-type object, a very incomplete example:
<emailMessage id="1">
<to>{userEmail}</to>
<from>{systemEmail}</from>
<subject>Account Information</subject>
<body>Dear {userName},
Here is the requested account information:
Password: {newPassword}
Thanks,
{adminName}
</body>
</emailMessage>

dim messag as CustomMailMessageObject = getMessage(1)
message.to = message.to.replace("{userEmail}", user.Email);
message.from = message.to.replace("{systemEmail}",
configuration.SystemEmail);
dim body as new StringBuilder(message.Body);
body.replace("{userName}", user.Name);
body.replace("{newPassword}", user.Password);
body.replace("{adminName}, configuration.AdminName);

This gives you the added flexibility of not having your emails hard-coded in
your application.

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top