Configuring an ASP.NET web app with GSuite Gmail SMTP

This one took me several days to configure as it seems like Google has been constantly upgrading its security rules and so I found a lot of solutions online that no longer work. It’s possible this article may get outdated soon but at the time of writing, this is what made my “Contact Us” page work with GSuite’s Gmail.

These are the following changes you will need to make:

  1. Domain Admin to allow users to enable 2-step verification

    • Login to the GSuite Admin Console using an Admin account
    • Navigate to Security
    • Click on Basic Settings
    • Enable the “Allow users to turn on 2-step verification”
  2. User to enable 2-step verification

    • Login to GSuite using the account that will be used for sending emails
    • On the My Account dashboard, click on “Sign-in & Security
    • On the section Signing in to Google, click on “2-Step Verification”
    • Turn on “2-Step Verification”
    • Fill your details and follow the instructions required to finish 2-step verification
  3. User to generate an app password

    • On the same User account, navigate to  Signing in to Google and click “App paswords”
    • Generate an app password and give it an app name
    • Copy the generated app password for use on step4 below
  4. Update your web application web.config

    <system.net>
       <mailSettings>
          <smtp from="{defaultFromEmail}" deliveryMethod="network">
             <network host="smtp.gmail.com" userName="{userEmail}" password="{appGeneratedPassword}" port="25" enableSsl="true">
          </smtp>
       </mailSettings>
    <system.net>

Those steps did the job for me. I did not need to enable less secure apps to be able to login.

🙂

Submit your review
1
2
3
4
5
Submit
     
Cancel

Create your own review

Average rating:  
 1 reviews
by Chris on Nicola Ayan - Blog
Thanks for sharing this

Glad someone figured this out, I was spent ages on it as well!