I was using the default MailMessage
and SmtpClient
classes for creating and sending HTML emails from a web forms website. The problem is I have a lot of hard coded HTML for formatting the email that gets sent. Is there a class that helps format emails for .NET? Any resources or suggestions would be appreciated.

- 154
- 1
- 3
- 8
-
Similar question: http://stackoverflow.com/questions/620265/can-i-set-up-html-email-templates-with-asp-net – Forgotten Semicolon Mar 02 '11 at 16:33
2 Answers
There's the MailDefinition class: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.maildefinition.aspx
The MailDefinition class can be used by controls to create a MailMessage object from a text file or a string that contains the body of the e-mail message. Use the MailDefinition class to simplify creating predefined e-mail messages to be sent by a control. If you want to send e-mail not using a control, see the System.Net.Mail class.
You can make text substitutions in the body of the e-mail message by passing to the CreateMailMessage method an IDictionary instance that maps strings to their replacements.
The MailMessage object created by the MailDefinition class is sent using the Send method of the SmtpClient class. To be able to send e-mail, you must configure an SMTP mail server in your Web.config file. For more information, see the Element (Network Settings).

- 72,686
- 18
- 132
- 173
You could create your email templates as razor views. Check out this blog post.

- 8,322
- 2
- 49
- 61