How to send email in ASP.NET C# MVC 3 (with sample working code)

Below is a sample working code for sending in a mail using C#, in the below example I am using google’s smtp server. The code is pretty self explanatory, replace email and password with your email and password values,

In case of any queries feel free to write in using the comment box. CHEERS !

public void SendEmail(string address, string subject, string message)  
    string email = "";  
    string password = "put-your-GMAIL-password-here";

    var loginInfo = new NetworkCredential(email, password);  
    var msg = new MailMessage();  
    var smtpClient = new SmtpClient("", 587);

    msg.From = new MailAddress(email);  
    msg.To.Add(new MailAddress(address));  
    msg.Subject = subject;  
    msg.Body = message;  
    msg.IsBodyHtml = true;

    smtpClient.EnableSsl = true;  
    smtpClient.UseDefaultCredentials = false;  
    smtpClient.Credentials = loginInfo;  

About Yasser Shaikh

Hello, I am a Web Dev, employed with Media.Net where I primarily work on ASP.NET MVC and Angular JS based developement.

Questions? Enquiries? Comments? Or even just want to say “Hi” to me, you are welcome to all of that. Just drop me a message at "" and I’ll get back to you as soon as possible.

Cheers !

  • Tayyyarciko

    hi .thnx for the sharing can you share full project in zip file .That would be very helpful.Best regards.

  • Swetha

    How can i work for sending email to multiple members by passing checkbox ‘s selected values

  • Amirreza


  • Pingback: How to: Sending email in .NET through Gmail | SevenNet()