gmail smtp

How to Send Emails Using Gmail SMTP with App Password

24 Jan, 25 | Aakash Chavhan | 92 | 0 |  2 |  0

Learn how to send emails securely using Gmail SMTP with App Passwords. This guide covers enabling 2FA, generating app passwords, and SMTP setup.

✅ How to Send Emails Using Gmail SMTP with App Password

If you're trying to send emails through your web application using Gmail SMTP, you're on the right path. Gmail provides a secure and reliable SMTP service, but due to Google’s strict security standards, you'll need to use App Passwords—especially when using a Gmail account created via Google Workspace (formerly G Suite) with 2-Step Verification enabled.

In this blog, we’ll walk you through the entire setup process for using Gmail SMTP to send emails securely.

🔐 Step 1: Enable 2-Step Verification

Before you can generate an App Password, you need to enable 2-Step Verification on your Google account.

How to Enable:

  1. Log in to your Gmail account.

  2. Go to Manage your Google Account.

  3. Navigate to Security.

  4. Under the Signing in to Google section, find 2-Step Verification and turn it ON.

  5. Follow the prompts to complete setup using your mobile device.


🔑 Step 2: Generate an App Password

Now that 2-Step Verification is enabled, you can generate an App Password specifically for your application.

Steps:

  1. While logged into your Gmail, go to Google Account.

  2. Click on Security.

  3. In the search bar at the top, type App passwords and click the result.

  4. You’ll be prompted to log in again.

  5. Under Select App, choose Mail.

  6. Under Select Device, choose Other and name it (e.g., "My Web App").

  7. Click Generate.

📌 Note the 16-character password displayed. This is your App Password and will be used instead of your normal Gmail password in the SMTP configuration.


📤 SMTP Configuration Details

Use the following SMTP settings in your application or email client:

  • SMTP Host: smtp.gmail.com

  • Port:

    • 587 (TLS)

    • 465 (SSL)

  • Encryption: TLS or SSL (as per your port)

  • Authentication: Yes

  • Username: Your full Gmail address (e.g., yourname@gmail.com)

  • Password: The App Password you generated


💻 Sample PHP Code Using PHPMailer

⚠️ Common Issues

  • App Password Not Working?

    • Double-check that 2-Step Verification is enabled.

    • Ensure you copied the App Password correctly (no spaces).

  • SMTP Connect() Failed?

    • Check firewall and internet restrictions.

    • Ensure port 587 or 465 is open.


✅ Conclusion

Using Gmail’s SMTP service with App Passwords adds an essential layer of security and reliability to your email-sending functionality. Whether you're building a contact form, a notification system, or a transactional email service, this method ensures your emails are sent securely and comply with Google’s standards.


Contact Us
COMMENTS

No comments