Sending an HTML Email with Visual Studio 2005

Posted by: Thom Robbins .NET Weblog, on 28 Jun 2006 | View original | Bookmarked: 0 time(s)

Question: I am trying to send an email with Visual Studio 2005 using System.Web.Mail and it keeps telling me that it is obsolete? What should I use? Also if you have an example of how to send an HTML email that would also help.

Answer: Within Visual Studio 2005 you can use the System.Net.Mail namespace. This contains the classes used to send email using SMTP. The MailMessage class is used to represent the content of an email message. The SmtpClient transmits email to the SMTP host that you designate for mail delivery. For example you can use the following code within a button of a Windows form to send an HTML email.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim client As New SmtpClient("smtp.server")
       
Dim toAddr As New MailAddress(trobbins@microsoft.com)  
       
Dim fromAddr As New MailAddress(trobbins@microsoft.com)
        Dim message As New MailMessage(fromAddr, toAddr)

        message.IsBodyHtml = True
        
message.Subject = "This is a Test"

        message.Body = "<html><body><b>This is an </b> <font color=red>HTML Message</font></body></html> "

        client.Send(message)

    End Sub

The email that is sent looks like the following

Advertisement
Free Agile Project Management Tool from Telerik
TeamPulse Community Edition helps your team effectively capture requirements, manage project plans, assign and track work, and most importantly, be continually connected with each other.
Category: ASP.NET | Other Posts: View all posts by this blogger | Report as irrelevant | View bloggers stats | Views: 1730 | Hits: 118

Similar Posts

  • "ADO.NET Entity data model" or "edmx" or "L2E" debug visualizer more
  • Html Encoding Code Blocks With ASP.NET 4 more
  • Debugger Visualizers not working in ASP.NET Medium Trust more
  • WebAii Testing Framework: From HTML to XAML and Back -- RadHtmlPlaceholder more
  • ASP.NET MVC: DevExpress Mail Demo more
  • Reporting Release History : Q2 2009 SP1 (version 3.1.9.807) more
  • Validation - Part 2 - Client-Side more
  • ASP.NET MVC Controls and Good versus Evil more
  • April's Toolbox Column Now Online more
  • Simple jQuery Delete Link For ASP.NET MVC more

News Categories

.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Data | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD