Gmail contacts-only inbox
Gmail only allow emails from contacts: three ways that work.
Gmail has no setting that only allows email from your contacts, because filters cannot check Google Contacts. You can get close three ways: a filter that archives everyone not on a list you type, a free Apps Script that checks your contacts every few minutes, or KeepKnown, which screens each sender as mail arrives and deletes nothing.
Last updated
Gmail filters match what you type into them: addresses, domains, words, sizes, and dates. They cannot check whether a sender is saved in Google Contacts, so there is no native rule for “everyone who is not a contact.” Google's filter guide lists every criterion Gmail supports.
The three workable options are below, from free and manual to automatic. Each one keeps mail recoverable in a label instead of deleting it.
Short answer
There is no contacts-only setting in Gmail.
For a contacts-only inbox, either maintain an allow-list filter, run a free Apps Script that reads Google Contacts, or use KeepKnown, which checks contacts, VIP domains, and people you have replied to and moves everyone else to KK:OUTSIDERS. Blocking senders one by one does not scale.
Option 1: build a native allow-list filter in Gmail
- Open Gmail on a computer and select Show search options (the sliders icon) in the search bar.
- In Has the words, enter -from:alice@example.com -from:yourcompany.com with one -from: entry for each person or domain you want to keep.
- Select Search. Everything in the results is mail the filter would move out of the inbox, so check it carefully.
- Select Create filter, tick Skip the Inbox (Archive it) and Apply the label, then create a label such as Not in contacts.
- Leave Also apply filter to matching conversations unticked until you trust the list, then select Create filter.
- Edit the filter every time you meet someone new, or their mail will keep skipping the inbox.
Option 2: a free Apps Script that reads Google Contacts
This Google Apps Script labels and archives inbox mail from anyone who is not in your Google Contacts or Other contacts. Set ARCHIVE to false to label only.
// Screen Gmail senders who are not in your Google Contacts.
// Runs in your own Google account. Nothing is sent to KeepKnown.
const LABEL_NAME = 'Not in contacts';
const ARCHIVE = true; // true: label and archive. false: label only.
const SEARCH = 'in:inbox newer_than:1d';
function screenInbox() {
const known = knownAddresses_();
const label = GmailApp.getUserLabelByName(LABEL_NAME) || GmailApp.createLabel(LABEL_NAME);
GmailApp.search(SEARCH, 0, 100).forEach(function (thread) {
const labelled = thread.getLabels().some(function (existing) {
return existing.getName() === LABEL_NAME;
});
const fromKnownSender = thread.getMessages().some(function (message) {
return known.has(addressOf_(message.getFrom()));
});
if (labelled || fromKnownSender) return;
thread.addLabel(label);
if (ARCHIVE) thread.moveToArchive();
});
}
function knownAddresses_() {
const known = new Set([Session.getActiveUser().getEmail().toLowerCase()]);
GmailApp.getAliases().forEach(function (alias) {
known.add(alias.toLowerCase());
});
let pageToken;
do {
const page = People.People.Connections.list('people/me', {
personFields: 'emailAddresses',
pageSize: 1000,
pageToken: pageToken,
});
(page.connections || []).forEach(function (person) {
addEmails_(known, person);
});
pageToken = page.nextPageToken;
} while (pageToken);
do {
const page = People.OtherContacts.list({
readMask: 'emailAddresses',
pageSize: 1000,
pageToken: pageToken,
});
(page.otherContacts || []).forEach(function (person) {
addEmails_(known, person);
});
pageToken = page.nextPageToken;
} while (pageToken);
return known;
}
function addEmails_(known, person) {
(person.emailAddresses || []).forEach(function (email) {
known.add(String(email.value).toLowerCase());
});
}
function addressOf_(from) {
const match = from.match(/<([^>]+)>/);
return (match ? match[1] : from).trim().toLowerCase();
}
The script checks your Google Contacts and Other contacts (people you have emailed) on a timer, so new mail can sit in the inbox for a few minutes. Apps Script has daily quotas and a 6-minute limit per run, and you maintain the code yourself. To let a sender through, add them to Google Contacts; mail you move back keeps its label and is not archived again.
Install the script
- Open script.google.com and select New project.
- Delete the sample code and paste the script.
- Next to Services, select the plus sign, choose People API, and select Add.
- Select screenInbox in the toolbar, select Run, and allow access to your Gmail and contacts.
- Open Triggers (the clock icon), select Add Trigger, choose screenInbox, a time-driven Minutes timer, and Every 10 minutes, then save.
Filter, script, or KeepKnown?
| Question | Gmail filter | Apps Script | KeepKnown |
|---|---|---|---|
| Knows your Google Contacts | No, only addresses you type | Yes, reads contacts on each run | Yes, plus VIP domains and people you have replied to |
| Keeps up with new contacts | No, edit the filter by hand | Yes | Yes |
| When mail is checked | On arrival | Every few minutes on a timer | As mail arrives |
| Setup | A few minutes in Gmail settings | Paste a script, add a trigger | Connect Gmail with Google authorization |
| Where strangers go | A label you choose | A label you choose | The KK:OUTSIDERS label; nothing deleted |
| Cost | Free | Free | From $12.99/month |
| Main limit | The list goes stale and gets long | Quotas, timers, and code you maintain | Paid plan; Gmail and Outlook only |
Option 3: contacts-only screening with KeepKnown
Contacts pass through
KeepKnown checks whether the sender is in Google Contacts, a VIP domain, or someone you have replied to.
Outsiders are recoverable
Messages from everyone else move to KK:OUTSIDERS instead of being deleted or permanently blocked.
No body reading
Routing uses the sender and your contacts, not the text of the message.
Check before you change anything
See how many non-contacts reach your inbox.
The free audit counts senders who are not in your contacts using message metadata only. It does not move or change any email.
No inbox changes during the audit.
Questions before you connect.
Can Gmail only allow emails from contacts?
Not natively. Gmail filters cannot check whether a sender is in Google Contacts. You can approximate it with a filter that archives mail from everyone except addresses you list, a free Apps Script, or a contact-based screener such as KeepKnown.
How do I stop emails from people not in my contacts in Gmail?
Create a filter with one -from: entry per trusted address or domain in Has the words, choose Skip the Inbox and a label, and keep the list updated. KeepKnown does the same from your live Google Contacts.
Is there an Apps Script to archive emails not in my contacts?
Yes. The script on this page reads Google Contacts with the People API, labels inbox mail from anyone else, and can archive it. Run it every 10 minutes with a time-driven trigger.
Does saving someone to Google Contacts keep them out of Spam?
Google says mail from senders saved in Google Contacts won't go to Spam. It does not hold back everyone else; that still needs a filter, a script, or a screener.
Will blocking unknown senders delete their email?
Blocking sends a sender's future mail to Spam, where Gmail deletes it after 30 days. A label-based filter, the script, or KeepKnown keeps the mail searchable instead.
Does KeepKnown read Gmail message bodies?
No. The contacts-only routing decision uses sender metadata and contact membership, not message body text.
Gmail contacts only
Only contacts reach the inbox. Outsiders move aside.