Code2care : TechZone Apps & Tutorials

Send Email using Gmail in C Sharp DotNet Code


Sending a email through code in .Net, you need to use System.Net.Mail and System.Net Classes.

Do check the SMTPClient details of gmail account.

  • Host : smtp.gmail.com
  • Post : 587 ( port may be different)
  • EnableSsl : true
  • DeliveryMethod : SmtpDeliveryMethod.Network
  • Timeout : 30000 (in ms)
  • Credentials : NetworkCredential(Address, Password)


  • using System.Net.Mail;
    using System.Net;
    
    var fromEmailAddress = new MailAddress("[email protected]", "From ABC");
    var toEmailAddress = new MailAddress("[email protected]", "To XYZ");
    const string fromEmailPassword = "your-password-here";
    const string subjectOfEmail = "Testing Email Sending from C# Code";
    const string bodyOfEmail = "Testing successful!";
    
    var smtp = new SmtpClient
    {
        Host = "smtp.gmail.com",
        Port = 587,
        EnableSsl = true,
        DeliveryMethod = SmtpDeliveryMethod.Network,
        Credentials = new NetworkCredential(fromEmailAddress.Address, fromEmailPassword),
        Timeout = 30000
    };
    using (var msg = new MailMessage(fromEmailAddress, toEmailAddress)
    {
        Subject = subjectOfEmail,
        Body = bodyOfEmail
    })
    {
        smtp.Send(msg);
    }

    Posts related to cSharp.


    1. Send Email using Gmail in C Sharp DotNet Code


    Posts related to dotNet.


    1. Send Email using Gmail in C Sharp DotNet Code


    Posts related to microsoft.


    1. Setting up RSS feeds notifications within Outlook

    2. Send Email using Gmail in C Sharp DotNet Code


    Posts related to gmail.


    1. Somethings not right Error Gmail Hangout

    2. 86 Gmail keyboard shortcuts that you may find Advantageous

    3. How to Undo-Revert Sent Email in Google Gmail

    4. Gmail Error Bad Request Your client has issued a malformed or illegal request

    5. Send Email using Gmail in C Sharp DotNet Code

    6. Enable-Disable Profile Pictures in Gtalk in Gmail


    Code2care : Lines of Code for Change
    Code2care is an initiative to publish and share varied knowledge in technical and non-technical areas gathered during day-to-day learnings and development activities.





    Android app on Google Play    








    Popular tags
    android
    x 175
    eclipse
    x 29
    notepadplusplus
    x 20
    macosx
    x 14
    sharepoint
    x 14
    html
    x 14
    mac
    x 13
    androidstudio
    x 11




    1000+ C Programs     PHP Tutorial     JSON Tutorial     Swift Tutorial     India Pinocdes     About Us     Privacy Policy


    Code2care © 2012-17