In my opinion programming means thinking, and it is fun. My vision is to teach programming in more understandable manner to the students from rural background. I support programming for everyone

Sending Email using your GMail Account in C#.NET

No comments

 

 

Use System.Net.Mail namespace, not the deprecated System.Web.Mail. Doing SSL with System.Web.Mail will get security problems

var client = new SmtpClient
            {
               
//create a host
                Host = "smtp.gmail.com",
               //gmail uses port number 587
                Port = 587,
               //Enable Secure Communication
                EnableSsl = true,
                //Set delivery method to Network
                DeliveryMethod = SmtpDeliveryMethod.Network,
               //Give the Credentials
                Credentials = new NetworkCredential("yourusername@gmail.com", "yourPassword"),
                //Set some timeout
                Timeout = 20000
            };

   eleven
 //Create a MailMessage Object
            using (var mailMessage = new MailMessage("yourusername@gmail.com", toEmailId)
            {
                //add subject and EmailBody(content) to Mail Message object
                Subject = “Subject of the Email”,
                Body = “Content of the Email”
            })
            {
                //Send the Message...
                client.Send(mailMessage );
            }

 

Suggestions appreciated………. 

Raghuveer

No comments :