Startups often face deliverability issues when sending emails from custom domains. This guide explains how to configure Sender Policy Framework (SPF) records by identifying valid mail sources, using correct syntax, and avoiding common configuration errors to improve email authentication.

Identifying Valid Mail Sources for Your Custom Domain

Imagine an early-stage founder who has just registered a custom domain for a small developer-tools project and now wants to write an SPF record that reflects every real mail source. Her working materials are modest: a one-page onboarding checklist, a spreadsheet of accounts, and a short list of tools the project actually uses. Nothing in this sketch is a test result or a recommendation for any deployment; it is a concrete example of how one author might organize the choices.

Her first artifact is a mail-source inventory with four columns: purpose, route, host or service, and owner. Two fictional rows show how entries are classified. In the first row, purpose reads customer onboarding messages, route reads outbound-only, host reads mailer.example-startup.test, and owner reads the founder. In the second row, purpose reads internal alert forwarding, route reads forwarded through a mailbox, host reads team.example-startup.test, and owner reads the operations volunteer. The host spellings are her own shorthand notes, not claims about what any provider accepts.

Her second artifact is a checklist page titled Domain Mail Sources, with sections for transactional sending, human mailboxes, and temporary tools. Under transactional sending she lists the one account used for sign-up confirmations. Under human mailboxes she lists the two people who reply to early users, each with a separate sending path. Under temporary tools she lists a form service that only receives notifications. This grouping makes a specific trade-off visible: she excludes the form service from the SPF record because it never sends from the domain, and she notes in the owner column that adding it later would require a new inventory row first.

Her third artifact is a short cover sheet titled SPF Working Notes, headed by three candidate labels for the record itself: Project Mail, Onboarding Mail, and Domain Mail. She decides to keep Project Mail as the internal label so the spreadsheet and the record share a name, even though another label might read more naturally to an outsider. The cover sheet also lists two open questions for a later section: which routes are outbound-only, and which addresses forward mail rather than originate it. These examples are drafted to explain the problem, not to describe a real business.

Understanding the Basic Syntax of an SPF TXT Record

For a Microsoft 365 custom domain, the documented basic syntax of an SPF TXT record is v=spf1 followed by valid mail sources and an enforcement rule. The v=spf1 element identifies the TXT record as an SPF TXT record. Valid mail sources can be expressed as domains, IP addresses, or both: an include: value names another service or domain as a valid source for the original domain's mail, and those values resolve to IP addresses through DNS queries; an ip4: or ip6: value has two elements, the type identifier and the public resolvable IP address of the originating email system, such as a single address or a range in CIDR notation.1

The enforcement rule tells the destination email system how to handle messages from sources not specified in the domain's SPF TXT record. The documented valid values are -all, a hard fail where unspecified sources are not authorized and mail should be rejected; ~all, a soft fail where unspecified sources may not be authorized and mail should be accepted but marked; and ?all, neutral, which the page says is used for testing and is not recommended in production.1

Look again at your own candidate label and the one-line description on your cover sheet, then turn them into a draft SPF record you can read aloud: a version marker such as v equals spf1, one or more mechanism tokens, and a closing all token. For a worked example, suppose your cover sheet says Project Mail, the description says human mailboxes plus one transactional route, and your inventory lists one sending host. A draft might read v=spf1 include:mail.example.net -all, where the include names the host you wrote down and the -all signals that unlisted senders should fail. You can then compare two variants side by side: -all versus ~all. Consider choosing ~all while the project is still adding tools, since it soft-fails rather than hard-fails; write the reason on the same line so the choice is not lost.

Keep the draft short and literal. Each include should trace back to a row in your spreadsheet, and if a host serves two purposes, note that once instead of listing it twice. You might mark uncertain rows with a question mark and leave them out of the record until you confirm the source. When you reread the draft, check that every token maps to something you wrote down, that the record sits within the length limit your notes mention, and that the closing token appears only once at the end.

Choosing Between Hard Fail (-all) and Soft Fail (~all)

The enforcement rule tells receiving systems what to do with mail from sources not listed in the domain's SPF TXT record. In the documented syntax, the closing token is either -all or ~all, and the record needs a version marker, valid mail sources, and this rule.1

The same source states that with -all, sources not specified in the record are not authorized to send mail for the domain, so messages should be rejected; actual handling depends on the receiving system, but mail is usually discarded. It recommends -all for Microsoft 365 domains because DKIM and DMARC are also recommended, and DMARC policy governs what happens to messages failing SPF or DKIM.1

For ~all, the source says unspecified sources may not be authorized, so messages should be accepted but marked. What actually happens depends on the destination system; examples given include quarantine as spam, delivery to the Junk Email folder, or inbox delivery with an identifier added. The source also notes that DMARC treats -all and ~all as SPF failures, but if a message has no DKIM signature, DMARC policy is effectively ignored when SPF ~all fails.1

Take your draft record and write two versions side by side: the documented sources ending in hard fail, and the same sources ending in soft fail. Keep everything before the final token identical, then read both aloud against your spreadsheet to see which ending you can honestly support. A project whose mail sources are fully listed and stable might prefer the hard version; one still adding tools every week might favor the soft version as a temporary choice.

You can revise the cover-sheet line to match whichever ending you select. For example, change “Project Mail — all known senders, strict” into “Project Mail — all known senders, soft while tools are added,” and note the date beside it. This makes the choice visible when you revisit the file, without implying the record has been published or checked by anyone else.

Consider writing a short comparison note for your own use: list what each ending would mean for a message sent from a source missing from your inventory, and which of your current tools you would need to confirm first. This is a thinking aid, not a service claim. If you later add a temporary tool, you can return to both versions and decide whether the ending still fits before updating the record.

Combining Include Directives with IP Addresses

The Microsoft 365 DNS records page says a single SPF record may contain several different includes but the total DNS lookups must not exceed 10. For local mailboxes with a built-in security add-on, or Exchange Online combined with another email system, it lists ip4 and ip6 entries alongside an include for the other mail system, with the values in the documentation's own example brackets replaced by whatever other systems send mail for your domain. An existing record is updated in place: the example contoso.com value starting with v=spf1 ip4:60.200.100.30 include:smtp.adatum.com -all gains include:spf.protection.outlook.com before the -all, rather than standing as a second SPF record.2

Take your draft record and add one conditional block after the existing include directives: a sender whose mail leaves from a fixed address you have written down. Read it as a separate mini-list inside the same record — an include for the route plus an ip4 element for the address you noted — rather than as a replacement for what is already there.

A worked shape might read: version marker, then two includes for the transactional and mailbox routes, then one ip4 entry for a small outbound relay whose address you recorded from your own spreadsheet, then your chosen ending. As a filled example, the block could be “ip4:198.51.100.24” sitting between the includes and the final all qualifier. You can compare it against the same record without that entry and decide which one you can still explain line by line.

Use your mail-source inventory to keep this honest. Each address in the record should point back to a row with a purpose and an owner, and if a single relay serves two purposes, note that once. If an address is not in the spreadsheet, consider leaving it out until you can add the row.

The choice is yours: a record with includes only, includes plus one address, or includes plus several. Whichever you pick, write a one-line reason beneath the cover sheet, such as “kept the relay address because onboarding mail passes through it,” so a later reader can see why the exception exists.

Avoiding Multiple SPF Records for One Domain

Microsoft 365 documentation states plainly that a domain can have only one SPF record—the TXT record that defines the domain's SPF. Multiple SPF records are not a valid configuration.2

When you already have an SPF record and need to add the Microsoft 365 value, edit the current record rather than adding a second one. The page's example starts with a TXT record at @ whose value is v=spf1 ip4:60.200.100.30 include:smtp.adatum.com -all; the correct update inserts include:spf.protection.outlook.com into that same value, keeping the existing ip4 entry and other include. The page labels as incorrect a setup with one record holding the old value and a second record holding only the Microsoft 365 include.2

The documented SPF structure has three parts: a declaration that it is an SPF record, the domains and IP addresses that should send email, and the enforcement rule.2

You can use your inventory to spot a second SPF-like line before you publish. If your domain already has one record from a signup wizard and you are about to add another, pause and compare the two strings character by character. For example, put version marker, include for one sending route, and ending in one column, then the same three fields for the other candidate. If both begin with the same version marker and both end in all, they are competing records rather than two additions to one policy; consider merging their includes into a single line instead of letting the newer one sit beside the older.

Your checklist page can carry a field for this. Try a row with these columns and filled values: Entry label, Project Mail; Existing string, version marker plus include plus all; Proposed change, add second include; Action, merge into the existing line and retire the duplicate. A second row might read: Entry label, Temporary tool; Existing string, none; Proposed change, add its include to Project Mail; Action, edit the one line rather than append a new one. These are author examples, not results.

After merging, reread the unified line against your inventory so each include still maps to a row you own. Keep the retired string in your notes as the prior version, with the date you revised it, so you can explain later why the record changed. You might also add a short question to the checklist: does any inbox setup screen offer to add its own record? If it does, note it there before accepting.

Verifying Configuration Against RFC Standards

Under the documented Exchange Online setup, the SPF record for a custom domain such as contoso.com is written as a TXT record in DNS: v=spf1 include:spf.protection.outlook.com –all. The same source states that for the onmicrosoft.com domain, Microsoft has already configured this framework, while the custom-domain record is described for an Exchange Online-only setup, not a hybrid one.3

The page also assigns DNS records to the other authentication methods it describes. DKIM, which adds a digital signature to email headers, relies on DNS records, and the source says DKIM should be enabled for all domains. DMARC defines behavior when SPF and DKIM fail, should be set to fail (p=reject), is configured through DNS records, and should be published for all second-level domains.3

Take your draft record and add a short standards-check note beside it, written in your own words rather than copied from a specification. For each term you used, jot one line saying what you believe it does: the version marker, the include directive, the ip4 entry, the all mechanism, and the qualifier in front of it. Where a line feels uncertain, mark it with a question rather than a guess.

You can then read the note back against your mail-source inventory. If an include points to a host that sends nothing for this domain, consider cutting it; if a row still has no matching term, add a line to the note before touching the record. A worked pairing might read: "include, transactional route, owner listed" and "ip4, small relay, needs confirmation."

Your options stay open. You might keep the note as a private appendix, fold it into the checklist page, or set it aside once the draft feels settled. If you fold it in, a plain row with two columns—term and my plain-language reading—is enough.

Frequently asked questions

What columns should I give my mail-source inventory?

Her first artifact is a mail-source inventory with four columns: purpose, route, host or service, and owner. Two fictional rows show how entries are classified.

How do I keep my draft SPF record short and literal?

Keep the draft short and literal. Each include should trace back to a row in your spreadsheet, and if a host serves two purposes, note that once instead of listing it twice.

What can I jot beside my draft record for each term I used?

Take your draft record and add a short standards-check note beside it, written in your own words rather than copied from a specification. For each term you used, jot one line saying what you believe it does: the version marker, the include directive, the ip4 entry, the all mechanism, and the qualifier in front of it.