Sample Code on how to send email using ASP.NET 2

For ASP.NET 2 you no longer using System.Web.Mail, but you will be using System.Net.Mail and the code to send email will be much simpler.

Below is the sample source code

 

                                                        
1 MailMessage mail = new MailMessage();
2
3 //set the addresses
4 mail.From = new MailAddress("me@mycompany.com");
5 mail.To.Add("you@yourcompany.com");
6
7 //set the content
8 mail.Subject = "This is an email";
9 mail.Body = "this is the body content of the email.";
10
11 //send the message
12 SmtpClient smtp = new SmtpClient("mail.yourdomain.com");
13
14 //to authenticate we set the username and password properites on the SmtpClient
15 smtp.Credentials = new NetworkCredential("username@yourdomain.com", "secret");
16 smtp.Send(mail);
17
18
  • 0 användare blev hjälpta av detta svar
Hjälpte svaret dig?

Relaterade artiklar

Sample Code on Sending Email using ASP.NET 1

Our mail server is configured with SMTP authentication and all your code need to use SMTP...

Query MySQL Database in ASP.net

1 2 3 <%@ Page Language="VB"...