- Create a web application in VS.NET
- Add a button control on the Page
- Import namespace System.Mail
- Write down following code in the click event of the button
protected void SendMail() { //Create Mail Message Object with content that you want to send with mail. MailMessage MyMailMessage = new MailMessage ("test@gmail.com", "myfriend@domain.com", "This is the mail subject", "Just wanted to say Hello"); MyMailMessage.IsBodyHtml = false; //Proper Authentication Details need to be passed when sending email from gmail NetworkCredential mailAuthentication = new NetworkCredential("test@gmail.com", "myPassword"); //Smtp Mail server of Gmail is "smpt.gmail.com" and it uses port no. 587 //For different server this details changes and you can //get it from respective server. SmtpClient mailClient = new SmtpClient("smtp.gmail.com", 587); //Enable SSL mailClient.EnableSsl = true; mailClient.UseDefaultCredentials = false; mailClient.Credentials = mailAuthentication; mailClient.Send(MyMailMessage); }


No comments:
Post a Comment