Send E-Mail from .NET application

.NET 2.0 has included System.Net.Mail code namespace for supporting email programming with .NET

Following is the code snippets for how to send mail from .NET application.


01MailMessage mail = new MailMessage();
02mail.To.Add("email1@email1.com");
03mail.To.Add("email2@email2.com");
04// you can add even add more to address in the same way.
05 
06mail.From = new MailAddress("from email address");
07// enter the email address. this address will show in the from field of recipient.
08  
09 
10mail.Subject = "Email using .NET";
11string Body = "Hi, this mail is to test sending mail";
12mail.Body = Body;
13mail.IsBodyHtml = true;
14 
15SmtpClient smtp = new SmtpClient();
16smtp.Host = "smtpserveraddress"; //Or Your SMTP Server Address
17// enter you smtp server name.
18 
19smtp.Credentials = new System.Net.NetworkCredential("smtp username", "smtp password");
20//Or your Smtp Email ID and Password
21  
22smtp.EnableSsl = true;
23// if required
24 
25smtp.Send(mail);

Responses to "Send E-Mail from .NET application"

Write a comment

Powered by IndiaGel.com