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
 
Back
Top