Home | 2.0 Content | Code Samples | Tips and Tricks | -- Tutorials -- | ASP.Net Books | Resources | Hosting
The Best Place Yet for ASP.Net - ASPNet101.com
Power Search


Don't Miss any New Content!
Sign up for Newsletter!

  Menu  
  Code Samples
Tips and Tricks
Tutorials
ASP.Net FAQ
Training
Resources
Hosting
Recommended Books
Home
 
     
  Our Sponsors :  
 
ASP Express WebHost4Life DotNetSlackers
 
     

69
If you find this site helpful, please donate to help keep it online


     
 
   

Sending Email with ASP.Net 2.0

If you haven't checked into it yet, there are several things that have changed from ASP.Net1.1 and ASP.Net 2.0, concerning email, however, it's still not very complicated.

The first thing you'll notice is that the namespace has changed from System.Web.Mail to System.Net.Mail. Also, now, to get the email working, there are two classes that need to be addressed:

  • MailMessage()
  • SmtpClient()
To use these, it will look something like this:
Dim Msg as MailMessage = new MailMessage()
Dim MailObj As New SmtpClient("mail.YourDomain.com")
Now - to add your To and From addresses, the Subject, Body and Body type, you'd do something like this:
Msg.From = new MailAddress("me@Here.com", "Big D")
Msg.To.Add(new MailAddress("you@There.com", "Knot A. Wildone"))
Msg.IsBodyHtml = "False"
Msg.Body = "this is the Email body"
Msg.Subject = "This is the Subject"
Notice, that the 'Friendly' name, can be easily added as a second argument, along with the direct email address. And Finally, to actually send the message, one line needs to be added:
MailObj.Send(msg)
Of course, if you needed some sort of confirmation statement, you could then add something like this:
label1.text="Email Sent!"
As was said earlier, several things have changed, and, it's not quite as easy as it was with ASP.Net version 1.1, but still, emailing in ASP.Net remains a very easy accomplishment!
   
Choose From Tutorials:
    Creating a Method to Return a DataSet in C#    
    Defining Error Displays Globally    
    Beginners Guide to Comparing Strings    
    Creating a Feedback Form    
    Beginners Guide: Scoping of Methods    
    Introduction to Parsing Strings    
    A Beginners Guide to the HyperinkField    
    Adding 'Last Updated' To Footer    
    Page Level Impersonation    
    Error Trapping in ASP.Net    
    Inserting and Updating with a SQLDataSource    
    Creating a Hit Counter    
    Using PreviousPage with a Master Page    
    Sorting/Filtering Fixed DataSet Results    
    Helper Functions    
    The Basics of Using SQL    
    A Beginners Guide to the Connection String    
    Querystring Results and SQL Statements    
    Membership/Roles with Remote DB    
    Beginners Guide to Com in ASP.Net    
    Multiple DropdownLists with AppendDataBoundItems    
    Creating a Login/Email/Activation Page    
    Creating a Popup Details Page    
    The Beginner's Guide to an ArrayList    
    Beginners Guide to the BulletedList    
    Configuring a Trusted SQL Srvr Connection    
    Emailing Form Results with ASP.Net 2.0    
    Adding Dynamic Content to Your Pages    
    Using TemplateFields    
    Menu User Control with Rollovers    
    Buttons and LinkButtons    
    Transferring Form Results to 2nd Page    
    Two Page Data Retrieval    
    Using the AdRotator Control    
    Using the QueryStringParameter    
    The 3 'Execute' Command Methods    
    Beginner's Guide to Master Pages    
    Displaying DataBase Information    
    Beginner's Guide to Themes    
    Sessions/Visitors Online    
    Sending Emails With ASP.Net 2.0    
    Sending Multiple Emails At Once    
    A Beginner's Guide to the GridView    
    Emailing Form Results    
    A Beginner's Guide to the DataSource Control    
    Inserting Data Into Two Tables    
    Coolest New v2.0 Additions    
    File System List With System.IO    
    Remote SQL Server/Web Matrix Server/WinXP Home    
    Understanding Regular Expressions    
    Creating a 'States' User Control    
    Parameterized Queries - Part 2    
    Iterating Through a List-Type Server Control    
    Creating an Online Bible    
    Beginner's Guide - Installing MSDE    
    Nesting Server Controls    
    Function Libraries    
    String Properties/Methods - Part 2    
    An Introduction to Validation Controls - Part I    
    String Properties/Methods - Part 1    
    Sending Mass Emails Part 2    
    Examining List Controls    
    Beginners Guide to Forms Authentication    
    If Not Page.IsPostBack    
    Using MySQL with ASP.NET    
    Single & Double Quotes in SQL    
    Matching Regular Expressions    
    Parameterized Queries in ASP.Net    
 
     
Home | 2.0 Content | Code Samples | Tips and Tricks | -- Tutorials -- | ASP.Net Books | Resources | Hosting
Send us your comments, questions or suggestions : Suggestions
Copyright © 2010 ASPNet101.com All Rights Reserved