Gmail in the terminal with OpenSMTPD, mail(1), and getmail6
===========================================================
(July 7th, 2026, updated September 25th, 2026)
If you use Gmail, you may have noticed that there is now a big honkin "Summarize this email" button at the top of every email. By poking around, you can turn this off (settings > uncheck "Smart features"), but the fact that it was just there one day was enough to push me into reading email in my terminal.
Note that this whole post is paraphrasings of the links in my sources. If the instructions look suspiciously similar, it's because I just lifted them [I have no shame]! Original research, schmoriginal schmresearch or something.
We'll need a few things to do this: some way to fetch mail from Gmail, some way to read and compose mail, and some way to give our outgoing mail to Gmail. I chose to use getmail6, OpenBSD's mail(1), and OpenSMTPD, respectively.
Gmail setup
-----------
First of all, we'll need an app password to be able to interact with Gmail with an external program. You can get one at https://myaccount.google.com/apppasswords, though note that you will first need to have 2-Step Verification enabled on your Google account.
Retrieving mail
---------------
Install getmail6, then edit ~/.getmail/getmailrc (replacing EMAIL with your address, APP_PASSWORD with your app password, and USER with your username on your computer):
[retriever]
type = SimpleIMAPSSLRetriever
server = imap.gmail.com
mailboxes = ("[Gmail]/All Mail",)
username = [email protected]
password = APP_PASSWORD
[destination]
type = Mboxrd
path = /var/mail/USER
[options]
read_all = false
delivered_to = false
received = false
delete = false
message_log = /home/USER/.getmail/log
read_all means only fetch *new* emails; delivered_to, received, and delete don't mark emails as delivered/received/deleted on Gmails's servers (so if we delete emails locally, Gmail won't delete them too). We're using a mbox destination because that's the only format mail(1) accepts. You could use ~ in the message_log path, but I chose to use the full path because it helps later if you have multiple Gmail accounts (see below).
Additionally, please please please do not expose your app password in plaintext like the example here. Instead, specify a password command.
You should now be able to:
getmail # fetch mail
mail # view mail
Sending mail
------------
In /etc/mail/secrets, insert the following line, which defines a secret called gmailinfo that contains your address and password.
gmailinfo [email protected]:APP_PASSWORD
Then, add these lines to your smtpd.conf:
action "relay_gmail" relay host smtp+tls://[email protected]:587 auth <secrets>
match from mail-from "[email protected]" for any action "relay_gmail"
This tells smtpd that whenever it sees an outgoing email from your Gmail address, it should relay it to Gmail.
Now, check your configuration, restart smtpd, and try and send an email!
** NOTE this exposes your IP address in the headers of any emails you send out, since Gmail keeps track of where the email originated.
smtpd -n
rcctl restart smtpd
mail [email protected]
Multiple Gmail addresses
------------------------
If you're anything like me, you need to keep track of your vast network of pseudonyms -- err, might have a work Gmail in addition to your personal address. These tools I'm using are very unix-y, so the cleanest solution I've found is to make separate users on your computer for each account.
getmail6 provides a script called getmails that fetches mail for multiple accounts, but I found that this didn't meet my needs. For example, it keeps track of previously retrieved mail differently if you get mail as a single user vs use the getmails script.
My best solution is just to make a new user for each email address, set them up all up the same as above, and then make a script to fetch all the mails:
bog$ cat ~/bin/mails
#!/bin/sh
getmail
doas -u user1 getmail
doas -u user2 getmail
doas -u user3 getmail
It can be used like this:
getmail # fetch mail for primary account
mails # fetch mail for all accounts
mail # read and write primary mail
doas -u user1 mail # read and write other account mail
I like to add
permit nopass USER as user1 cmd mail
permit nopass USER as user1 cmd getmail
to my doas.conf to allow me to fetch and read mail for my other Gmail accounts without entering a password.
Sources
-------
https://www.bowaggoner.com/bomail/getmail.html
https://tales.mbivert.com/on-openbsd-sendmail-and-gmail/
https://getmail6.org/documentation.html
getmails(1)
smtpd.conf(5)
~/terminal-gmail