Day 2 · DNS, mail servers & hosting
Google Workspace and Microsoft 365 email: setup, relays and migration
Course contents
Most organizations don’t run mail servers; they rent mailboxes from Google or Microsoft. That moves the work, it doesn’t remove it: the provider runs the servers, but you own the domain, its DNS records, the list of systems that send as your domain, the settings that decide how mail flows, and every migration in and out. This lesson covers the two big platforms side by side, then the part where most outages happen: moving a domain from one provider to another.
What you control, what they run
| The provider runs | You are responsible for |
|---|---|
| MX servers, spam and malware filtering, mailbox storage | The domain and every DNS record in it |
| Outbound servers and their IP reputation | Turning on DKIM for your domain (it’s not on by default) |
| Webmail, apps, IMAP/POP/Exchange endpoints | Your DMARC policy and reading its reports |
| Backups against their own failures | Users, groups, aliases, shared mailboxes, licenses |
| Which apps, devices and SaaS services send as your domain | |
| Retention, legal hold and protection against your own mistakes (deleted data) |
Google Workspace
-
Verify the domain. The Admin console gives you a TXT record (
google-site-verification=...). Publish it at the root of the domain and click verify. Keep the record afterwards. -
MX. Google’s current instructions for a new domain are a single record:
smtp.google.comwith priority 1. Domains set up before 2023 usually have the older set of five (aspmx.l.google.comat 1,alt1/alt2at 5,alt3/alt4at 10), which still works. Use one set or the other, never a mix.dig +short airbnb.com MX1 aspmx.l.google.com. 5 alt1.aspmx.l.google.com. 5 alt2.aspmx.l.google.com. 10 alt3.aspmx.l.google.com. 10 alt4.aspmx.l.google.com. -
SPF:
v=spf1 include:_spf.google.com ~all, plus any other services that send for you (lesson 8 explains~allvs-all). -
DKIM. In the Admin console under Apps → Google Workspace → Gmail → Authenticate email, generate a 2048-bit key. Google shows a TXT record for
google._domainkey.example.com(selectorgoogleby default). Publish it, wait until it resolves, then click Start authentication. -
DMARC: a TXT record at
_dmarc.example.com, starting withp=noneand a reporting address (lesson 10).
Sending from devices and applications (printers, scanners, monitoring systems, web apps):
- SMTP relay service (
smtp-relay.gmail.com, port 587 or 465): configured in the Admin console; accepts mail from your registered IP addresses and/or with SMTP authentication, and can relay for your domains. The right choice for multifunction printers and servers. - Gmail SMTP (
smtp.gmail.com, port 587/465): sends as one user, with OAuth or an app password, and counts against that user’s daily sending limit. - Neither is meant for bulk or marketing mail: Google enforces per-user and per-relay limits and suspends accounts that exceed them. Use an ESP for that.
Groups and shared addresses. Google Groups serve as distribution lists (team@) and as collaborative inboxes (support@ handled by several people). A user can also delegate their mailbox to an assistant. Aliases (alternate addresses) are free; catch-all routing exists, but a catch-all address collects mostly spam and makes directory-harvest attacks look successful, so avoid it.
Microsoft 365 (Exchange Online)
-
Verify the domain: a TXT record
MS=ms12345678from the admin center. -
MX: the admin center shows a record such as
example-com.mail.protection.outlook.com(the domain with dots turned into dashes). Microsoft has also introduced a newer MX format undermx.microsoftthat supports DNSSEC and DANE. Use exactly what the admin center shows for your tenant.dig +short github.com MX0 github-com.mail.protection.outlook.com. -
SPF:
v=spf1 include:spf.protection.outlook.com -all, plus your other senders. -
Autodiscover: CNAME
autodiscover.example.com→autodiscover.outlook.com, so Outlook and phones configure themselves. -
DKIM: in the Microsoft Defender portal (Email authentication settings → DKIM), Microsoft gives you two CNAME records,
selector1._domainkeyandselector2._domainkey, pointing to keys that Microsoft hosts and rotates for you. The target format changed in 2025 for new domains, so copy the exact values the portal shows instead of building them from an example. Publish them, then enable signing. Use 2048-bit keys. -
DMARC, as for Google.
Sending from devices and applications has three options, which Microsoft documents as:
| Option | How | Good for | Watch out |
|---|---|---|---|
| SMTP AUTH client submission | smtp.office365.com:587, a licensed mailbox and its credentials | A device or app that can authenticate | Basic-auth retirement: needs OAuth eventually; per-mailbox limits |
| Direct Send | Connect to your MX endpoint on port 25, no auth | Devices that can’t authenticate, sending only to your own users | Anyone can do the same; Microsoft lets you reject Direct Send, and most tenants that don’t need it should |
| SMTP relay with a connector | Connect to your MX endpoint, accepted because of your static IP or certificate | Sending to external recipients from on-premises servers and devices | Requires a static public IP and an inbound connector |
Microsoft also enforces sending limits per mailbox (recipients per day, messages per minute) to stop user mailboxes from being used for bulk mail. As with Google, newsletters and application mail at volume belong on an ESP.
Shared mailboxes (info@, sales@) need no license of their own up to the storage limit, and users open them with their own credentials; never share one password among a team. Distribution groups and Microsoft 365 Groups play the role of Google Groups.
Filtering gateways in front of the MX
Many companies route incoming mail through a third-party security gateway (Proofpoint, Mimecast and others) before it reaches Google or Microsoft: the MX points to the gateway, the gateway forwards to the provider. Two things to configure, or authentication breaks:
- The provider now sees every message arriving from the gateway’s IPs, so SPF checks of the original sender fail. Microsoft calls the fix Enhanced Filtering for Connectors (skip listing), and Google has an equivalent inbound gateway setting: both tell the provider to look past the gateway to the real sending IP.
- Lock down the provider’s own MX endpoint so it accepts mail only from the gateway; otherwise attackers deliver straight to it and skip your filtering.
Migrating a domain without losing mail
A migration moves three things: the mailboxes’ content, the routing (MX and other DNS), and the users’ apps. Mail must keep flowing the entire time, and in DNS, nothing changes instantly. A plan that works:
Two weeks before
- Inventory everything: mailboxes and their sizes, aliases, groups and their members, shared mailboxes, forwarding rules, mailbox permissions, and every system that sends mail as the domain (your SPF record and DMARC reports are the best source).
- Create the users, groups and aliases at the new provider. Verify the domain there; it can be verified at both providers at the same time.
- Set up DKIM at the new provider now (the selector names usually differ, so both providers’ keys can be published side by side) and add the new provider to SPF, so mail sent from either side passes during the transition.
Two days before
- Lower the TTL of the MX record (and SPF, autodiscover) to 300 seconds.
- Start the pre-stage copy: migrate the bulk of the old mail while users keep working on the old system. Use the new provider’s migration tools (Google Workspace’s data migration service, Microsoft’s IMAP and Exchange migration batches), or imapsync for IMAP-to-IMAP:
imapsync --host1 imap.old-provider.example --user1 alice@example.com --password1 "$OLD_PASS" \
--host2 imap.gmail.com --user2 alice@example.com --oauthaccesstoken2 "$TOKEN" \
--automap --syncinternaldates
# run it again later: it copies only what's new (the delta)
Cutover day
- Change the MX to the new provider at a quiet time. From now on, new mail starts arriving at the new provider as caches expire; senders with an old cached answer still deliver to the old one for a while, so don’t switch off the old system.
- Run the delta sync, so mail that arrived on the old side shows up on the new side.
- Change autodiscover, then move users’ apps and phones (many will need a new profile).
The weeks after
- Keep running delta syncs for a week or two, until the old system receives nothing new. Then remove the old provider from SPF, remove its DKIM keys, and only then cancel it.
- Raise the TTLs again. Watch DMARC reports for senders you forgot.