Gmail SMTP Setup Guide: Settings, App Passwords, Limits and Fixes
Complete Gmail and Google Workspace SMTP configuration — server settings, app passwords, OAuth 2.0, sending limits, relay options and every common error solved.
Complete Gmail and Google Workspace SMTP configuration — server settings, app passwords, OAuth 2.0, sending limits, relay options and every common error solved.
Here are the values you need. Everything else in this guide explains how to make them work.
Server: smtp.gmail.com
Port: 587 (STARTTLS) or 465 (SSL/implicit TLS)
Username: your full email address, e.g. you@gmail.com
Password: a 16-character app password (not your account password)
Encryption: required
Auth: LOGIN / PLAIN over TLS, or XOAUTH2Both ports work identically well. Use 587 unless your library handles implicit TLS more cleanly.
Google stopped accepting account passwords for SMTP when it retired "Less secure app access" in 2022. Every SMTP client now needs either an app password or an OAuth 2.0 token. If you are seeing 535-5.7.8 Username and Password not accepted, this is almost certainly why.
App passwords require 2-Step Verification on the account. If the option is missing from your Google Account settings, 2-Step Verification is not enabled yet — turn it on first.
Create one app password per application. When you rotate or revoke one, nothing else breaks.
Workspace accounts add an administrative layer that personal Gmail does not have.
For Workspace, using smtp-relay.gmail.com on port 587 with an IP allow-list is the supported production pattern. It avoids per-user credentials entirely.
For production systems that send on behalf of users, OAuth is the right approach: tokens are scoped, expire naturally, and can be revoked per user without touching a password.
The flow:
https://mail.google.com/ scope.The XOAUTH2 payload is a Base64-encoded string of the form:
user=you@example.com^Aauth=Bearer <access_token>^A^Awhere ^A is the \x01 control character. Most mature libraries construct this for you — you supply the address and token.
Access tokens last about an hour. Refresh proactively rather than waiting for a 535, and cache the token so you are not calling the token endpoint on every message.
| Account type | Daily limit | Recipients per message |
|---|---|---|
| Free Gmail | 500 per day | 100 |
| Workspace (SMTP submission) | 2,000 per day | 2,000 |
| Workspace SMTP relay | 10,000 per day per user | 100 per message |
Additional constraints:
550 5.4.5 Daily sending quota exceeded.Gmail is not a bulk email platform. If you are sending marketing campaigns or more than a couple of thousand transactional messages a day, use a dedicated provider. Gmail's limits and abuse controls are not designed for that workload, and hitting them repeatedly can suspend the account.
### 535-5.7.8 Username and Password not accepted
### 534-5.7.14 Please log in via your web browser
Google flagged the sign-in as suspicious, usually because the server is in a different country from your normal activity. Sign in from a browser once, complete any verification prompt, then retry. For a headless server, switch to OAuth — this error does not occur with tokens.
### 550-5.7.1 Daily sending quota exceeded
You hit the limit. Wait for the rolling window to clear and move volume to a transactional provider.
### 421-4.7.0 Try again later
Temporary rate limiting from too many connections or too rapid a send rate. Reduce concurrency to two or three connections, add exponential backoff, and reuse connections instead of reconnecting per message.
### 550-5.7.26 Unauthenticated email is not accepted
You are sending as a custom domain without proper SPF/DKIM alignment. Configure authentication for that domain, or send as the Gmail address itself.
### Connection times out
Port 587 or 465 is blocked by your network. Cloud providers and corporate firewalls commonly filter outbound mail ports. Test from the same environment your application runs in.
Gmail lets you send as you@yourcompany.com through the "Send mail as" feature. Two important caveats:
First, you must verify ownership of the address. Second, and more importantly, if that domain has a DMARC policy of quarantine or reject, mail sent this way may fail alignment unless the domain's SPF record includes Google. Add:
v=spf1 include:_spf.google.com ~alland configure DKIM signing for the domain in the Workspace admin console. Without both, your own DMARC policy will reject your own mail — a genuinely confusing failure mode.
Gmail SMTP is excellent for low-volume, internal, or development use. Move to a transactional provider when you need any of the following:
Providers like SendGrid, Postmark, Mailgun and Amazon SES all offer SMTP relays, so the migration is a configuration change rather than a rewrite.
Configuration errors with Gmail are easy to make and produce error messages that point in the wrong direction. Before shipping, run smtp.gmail.com on your chosen port through SMTPTester with the exact credentials your application will use. In a few seconds you will know whether the port is reachable, TLS negotiates, and the app password is accepted — and if it is not, you will see the raw server reply rather than your framework's paraphrase of it.
Apply what you just learned. Free, no signup, results in seconds.
Open the tool →A complete guide to testing SMTP servers — online testing, telnet and openssl commands, TLS verification, authentication checks and a repeatable diagnostic workflow.
DeliverabilityHow bounces work, the difference between hard and soft bounces, how to parse DSN messages, build a suppression list, and keep bounce rates under control.