How to configure Gmail SMTP

To create an App Password for Gmail SMTP (to securely send emails from your application), follow these steps:


Prerequisites

  1. Enable 2-Step Verification: App Passwords are only available if 2-Step Verification is enabled on your Google Account.
  2. Gmail SMTP Settings:
    • SMTP Server: smtp.gmail.com
    • Port: 587 (for TLS) or 465 (for SSL)
    • Authentication: Enabled
    • Encryption: TLS or SSL

Step-by-Step Instructions

1. Enable 2-Step Verification

  1. Go to your Google Account Security Settings: https://myaccount.google.com/security
  2. Under “Signing in to Google”, enable 2-Step Verification:
    • Click 2-Step Verification and follow the steps to set it up.

2. Generate an App Password

  1. Go to the App Passwords page: https://myaccount.google.com/apppasswords
  2. Log in if prompted.
  3. Under “Select the app and device you want to generate the app password for”:
    • For Select App, choose Mail or select Other (Custom Name) and name it (e.g., My SMTP App).
    • For Select Device, choose the device or select Other and name it.
  4. Click Generate.
  5. Copy the generated 16-character App Password. You won’t see it again after leaving the page.

3. Use the App Password in Your Application

  • Use this App Password as the SMTP password in your application instead of your Google Account password.

Example SMTP configuration:

  • SMTP Server: smtp.gmail.com
  • Port: 587 (TLS) or 465 (SSL)
  • Username: Your full Gmail address (e.g., your-email@gmail.com)
  • Password: The 16-character App Password.

4. Test Your SMTP Connection

Send a test email from your application to ensure everything works correctly.


Notes

  • If you’re using Gmail’s SMTP in production, remember to handle sensitive data (like App Passwords) securely using environment variables or secret management tools.
  • Google may block SMTP connections if it detects suspicious activity. Make sure your application adheres to Gmail’s usage policies.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *