DEV Community

Cover image for The macOS Terminal Email Setup Nobody Talks About
Chitransh Gupta
Chitransh Gupta

Posted on

The macOS Terminal Email Setup Nobody Talks About

A while ago, while watching a video about "How Email Works?" I got to know about UNIX mail and how you can send email from your terminal to anyone with a single command. I set it up with Gmail, went through 2FA, App Passwords, and a handful of extra steps, and finally got to excitedly send a test email to a friend.

Email from my terminal to my friend.

Getting there was some work, and I wanted one thing: my own domain in that sender address instead of @gmail.com.

While looking around, I remembered Resend where I had set up my domain and it had been refreshingly simple. A quick check confirmed they have their own SMTP service that uses an API key to send emails from your verified domain. Perfect!

This guide will show you how to set up your macOS terminal to send emails using Resend. Once it's configured, you can send a quick note from a script, get updates from a long-running build, or have an AI agent ping you when a task completes, all without leaving your shell.

Prerequisites

Prefer a one-command setup? Run the setup script directly. It handles everything interactively and sends a test email at the end. Otherwise, follow the guide below to understand exactly what is happening under the hood.

Download the script, unzip it, and run:

chmod +x resend-macos-setup.sh && ./resend-macos-setup.sh

Setup

macOS comes pre-built with Postfix, the default Mail Transfer Agent (MTA) which works on-demand. Whenever you send an email from your terminal, it is put in a local queue and Postfix tries to authenticate with your SMTP server. Once the authentication is successful, it relays the message from the queue to Resend, which then handles delivery to the destination.

Let's configure Postfix to send messages to your Resend SMTP server.

Step 1: Configure Postfix as a Relay Host

A relayhost is an intermediate mail server that receives your local emails and relays them to their destination. In this case, you will be using Resend as your SMTP provider.

Run the following command in your terminal:

sudo nano /etc/postfix/main.cf
Enter fullscreen mode Exit fullscreen mode

This will open the Postfix config file. Scroll to the bottom of the file and add the following lines to point Postfix to Resend's SMTP server:

mydestination =
relayhost = [smtp.resend.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = encrypt
smtp_sasl_mechanism_filter = login
smtp_generic_maps = hash:/etc/postfix/generic
local_transport = error:local delivery disabled
Enter fullscreen mode Exit fullscreen mode

๐Ÿ”ง View Configuration Details
Setting Purpose
relayhost Sends all mail through Resend's SMTP server
smtp_sasl_auth_enable Enables authentication
smtp_sasl_password_maps Points to the file with your Resend API key
smtp_sasl_mechanism_filter = login Ensures Postfix uses the LOGIN handshake required by Resend
smtp_tls_security_level = encrypt Mandates encryption to protect your API key during transit
smtp_generic_maps Maps your local Mac username (eg., cheeto@MacBook.local) to a verified domain email
local_transport = error: ... Prevents Postfix from trying local delivery
mydestination = (empty) Forces Postfix to treat every email as external and send it to relay

By default, your Mac tries to send mail as localuser@hostname.local, which modern servers like Resend will block. So, we use generic maps to rewrite that local address to your verified domain. The local_transport and mydestination settings act as a one-way street sign. Without them, Postfix would try to deliver your email locally to your Mac, silently succeeding at "delivery" while your message goes nowhere. These two settings together tell Postfix that every message is outbound.

Step 2: Secure Your Authentication Credentials

To allow Postfix to log in to Resend, you need to create a credential file and compile it into a format the system can read quickly. Run the following commands in your terminal:

sudo bash -c 'echo "[smtp.resend.com]:587 resend:YOUR_RESEND_API_KEY" > /etc/postfix/sasl_passwd'

sudo chmod 600 /etc/postfix/sasl_passwd

sudo postmap /etc/postfix/sasl_passwd

sudo chmod 600 /etc/postfix/sasl_passwd.db
Enter fullscreen mode Exit fullscreen mode

Replace YOUR_RESEND_API_KEY with the full key from your Resend dashboard (it usually starts with re_).

โš ๏ธ Do this now โ€” Clear your shell history

The command above writes your API key inline, which means it will be saved to your shell's history file (.zsh_history or .bash_history). After running it, clear the entry:

# zsh
fc -p
Enter fullscreen mode Exit fullscreen mode
# bash
history -d $(history 1)
Enter fullscreen mode Exit fullscreen mode

postmap compiles your credentials into a fast lookup database that Postfix can read. The chmod 600 step is not optional. Without it, your API key sits in a plain-text file readable by any process on your machine.

Step 3: Map Your Local User to a Verified Domain

By default, your Mac tries to send mail from username@hostname. Resend will reject this non-verified address, so you must use a generic map to rewrite your local identity to your real, verified email address. Run the following commands in your terminal:

sudo bash -c 'echo "$(whoami)@$(hostname) SENDER@YOURDOMAIN.COM" > /etc/postfix/generic'

sudo postmap /etc/postfix/generic
Enter fullscreen mode Exit fullscreen mode

Replace SENDER@YOURDOMAIN.COMwith your verified Resend email. For example, cheeto@cheeto.dev

๐Ÿ› ๏ธ Having issues? Verify your hostname

Postfix uses its own internal $myhostname to match addresses against the generic map. If it differs from what $(hostname) returns in your shell, the map never fires, Resend rejects the address, the queue empties, and nothing is delivered with zero error messages.

Run this to check:

postconf myhostname
Enter fullscreen mode Exit fullscreen mode

The output should match $(whoami)@$(hostname) exactly. If it doesn't, replace the $(hostname) part of the command above with the exact output of postconf myhostname and re-run it.


This creates a mapping file to replace your Mac's local identity ($(whoami)@$(hostname)) with your verified domain. Running postmap then compiles this into a .db binary that Postfix can actually read and query.

Step 4: Start/Reload Postfix

Postfix on macOS is "on-demand," meaning it doesn't run as a persistent background service. It spins up when needed. Run this to start it and load your new configuration in one go:

sudo postfix start; sudo postfix reload
Enter fullscreen mode Exit fullscreen mode

If Postfix was already running, the start command will say so. That is not an error, just ignore it. The reload is what picks up your config changes.

Testing your Configuration

Send a test email with the command below:

echo "Hello from my Mac Terminal via Resend" | mail -s "Postfix Test with Resend" recipient@example.com
Enter fullscreen mode Exit fullscreen mode

Replace recipient@example.com with the actual email address where you want to receive the message.

Confirming Success

Run this to check the local queue:

mailq
Enter fullscreen mode Exit fullscreen mode

If it returns Mail queue is empty, Postfix has handed the message off. That does not mean it was delivered yet. Head to the Emails section of your Resend Dashboard to confirm the actual delivery status.

๐Ÿ› ๏ธ Having issues?

Open a second terminal tab and run:

sudo tail -f /var/log/mail.log
Enter fullscreen mode Exit fullscreen mode

This gives you a live view of exactly what Postfix is doing when you send. If something is failing, the error will show up here in real time.


Resend Dashboard showing email successfully delivered.


Alternative: A Faster Setup

If Postfix feels like overkill, msmtp is a lightweight, relay-only client that is much easier to configure. It doesn't run in the background and simply sends your mail directly to Resend when you call it.

Installation

brew install msmtp
Enter fullscreen mode Exit fullscreen mode

Create and Configure the .msmtprc File

nano ~/.msmtprc #No sudo needed
Enter fullscreen mode Exit fullscreen mode

Paste the following into the file:

defaults
auth           on
tls            on          # STARTTLS on port 587 for encrypted connection
tls_starttls   on
logfile        ~/.msmtp.log

account resend
host smtp.resend.com
port 587
from SENDER@YOURDOMAIN.COM
user resend
password YOUR_RESEND_API_KEY

account default : resend
Enter fullscreen mode Exit fullscreen mode

Replace YOUR_RESEND_API_KEY with the full key from your Resend dashboard and SENDER@YOURDOMAIN.COM with your verified Resend email.

Secure Permissions

This file contains your plain-text API key. You must lock it down to owner-only access or msmtp will refuse to run for security reasons:

chmod 600 ~/.msmtprc
Enter fullscreen mode Exit fullscreen mode

Send a Test Email

Verify that your setup is working properly by sending a test email using the command below:

printf "Subject: msmtp Test via Resend\nTo: recipient@example.com\n\nHello from msmtp via Resend." | msmtp recipient@example.com
Enter fullscreen mode Exit fullscreen mode

Replace recipient@example.com with the actual email address where you want to receive the message.

Unlike Postfix, msmtp gives you instant feedback directly in your terminal. If the connection to Resend fails, you will know immediately.

Real-World Use: AI Agent Notifications

If you're running Claude Code, Codex, or any local agent loop, you can now give your agent the ability to send email with a single shell command:

echo "Task complete: dependency audit finished. 3 issues found." | \
  mail -s "Agent Report: $(date)" SENDER@YOURDOMAIN.COM
Enter fullscreen mode Exit fullscreen mode

Add this as a final step in any agent workflow. No Slack bot, no webhook, no extra API to set up. Just your terminal, talking back to you.

Top comments (0)