.Net Basic

This blogs gives introduction to C#.NET programming for beginners. This blogs assumes that you have no programming experience whatsoever. It's a lot easier than you think, and can be a very rewarding hobby!after Refer this blog

23 June 2009

Sending Email By using C#.net

In this coding we need to change "from@gmail.com", "to@gmail.com" and "Password"..

MailMessage mail = new MailMessage();
SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress("from@gmail.com");
mail.Subject = "Test Mail";
mail.Body = "This is for testing SMTP mail from GMAIL";
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("From@gmail.com", "Password");
SmtpServer.EnableSsl = true;
// send mail to With Attachement
System.Net.Mail.Attachment attachment;
attachment = new System.Net.Mail.Attachment("c:\\DSC00081.JPG");
// Send mail to With HTML Page
mail.IsBodyHtml = true;
string htmlBody = "create html page";
mail.Body = htmlBody;
MessageBox.Show("mail Send");
catch (Exception ex)

Labels: , , ,