How to set up DMARC/DKIM/SPF for Azure Virtual Machines

Updated on 23 Oct 2026: We updated the Azure VM setup for current outbound networking and DMARC enforcement.
An Azure Virtual Machine can send authenticated mail when its sending domain has one SPF record, a DKIM signature added by the mail transfer agent, and a DMARC record. Direct delivery also needs a static public outbound IPv4 address, matching forward and reverse DNS, a stable SMTP hostname, and access to TCP port 25. Azure does not create these email authentication settings for a VM.
Standard Enterprise Agreement and MCA-E subscriptions can send directly on port 25. Most other Azure subscription types cannot. On those subscriptions, configure the application or mail transfer agent to use an authenticated SMTP relay on port 587, then publish the SPF and DKIM values supplied for that relay instead of authorizing the VM public IP.
Choose the mail route first
Do not publish an Azure VM IP in SPF until that IP sends mail directly to recipient MX servers. A VM that submits mail to a relay on port 587 is not the internet-facing sender.
Configure the VM's sending identity
Azure Virtual Machines has no sender-domain verification wizard. For direct delivery, adding the domain means giving the VM a stable public identity, publishing the matching DNS records at the authoritative DNS host, and configuring the application to use that domain in its visible From address and SMTP envelope sender. Use Azure DNS only when the domain's public nameserver delegation points there; private DNS zones are not visible to receiving mail servers.
Direct delivery on port 25
- Public identity: Use a static Azure public IPv4 address.
- DNS identity: Point mail.example.com to that IP and set its PTR back to mail.example.com.
- Authentication: Authorize the public IP in SPF and sign mail on the VM with DKIM.
- Subscription: Use a standard EA or MCA-E subscription, or an approved Enterprise Dev/Test exemption.
Authenticated relay on port 587
- Connection: Submit with TLS and authentication on port 587.
- SPF source: Publish the relay's required SPF mechanism at your envelope domain when it supports a custom return path.
- DKIM source: Publish the relay's supplied TXT or CNAME selector records and enable signing, or retain signing on the VM if supported.
- Envelope sender: Use your domain when the relay supports a custom return path.
The following public IP and PTR steps apply to direct delivery. For authenticated relay, complete sender-domain verification in the relay's configuration. Replace example.com and 203.0.113.10 throughout with your domain and verified outbound IP.
- Reserve the IP: In Azure portal, open the VM, select Networking, open its network interface and IP configuration, then open the Public IP resource. Confirm Standard SKU, IPv4, and Static assignment.
- Publish forward DNS: Create an A record for mail.example.com that returns the static public IP. Do this before setting reverse DNS because Azure validates the forward lookup.
- Set reverse DNS: Run the Azure CLI command below in Cloud Shell. Azure supports one PTR per public IPv4 resource and requires the trailing dot in the reverse FQDN.
- Set the SMTP name: Configure the mail transfer agent to announce mail.example.com in EHLO. The PTR, A record, and EHLO name should match.
- Set the sender domains: Use user@example.com in From and bounce@example.com as the envelope sender. Their organizational domains then match for DMARC through SPF.
Azure CLI reverse DNS configurationBASH
az network public-ip update \ --resource-group mail-rg \ --name mail-public-ip \ --dns-name mail-example-com \ --reverse-fqdn mail.example.com.

Azure portal public IPv4 address and PTR configuration
Port 25 restriction
If direct SMTP times out, check the subscription type before changing DNS. Enterprise Dev/Test customers can run Cannot send email (SMTP-Port 25) under Diagnose and Solve on the virtual network. After an exemption, stop, deallocate, and restart the VM. Other blocked subscription types need an authenticated relay on port 587.
Confirm outbound connectivity and the sending IP
For API versions released after March 31, 2026, new Azure virtual networks default to private subnets. The Azure portal also defaults to private subnets. VMs in those subnets need explicit outbound connectivity to reach recipient mail servers or an SMTP relay. Existing virtual networks are not automatically changed. See Microsoft's default outbound access guidance.
- Configure egress: Use a static public IP attached to the VM, or an explicit outbound path such as NAT Gateway or Azure Firewall.
- Check the actual sender: NAT Gateway or a routed firewall can change the source IP even when the VM has its own public IP. For direct SMTP, authorize every possible sending IP in SPF and configure its PTR.
- Check network rules: Allow outbound TCP 25 for direct delivery or TCP 587 for authenticated submission in the network security group and guest firewall. Check Azure Firewall rules and routes when present.
- Keep the subscription check: An allowed network security group rule does not remove Azure's subscription-level port 25 block.
Run a TCP connection check from the VM against the destination used by the actual route. Replace the example hostname with the relay hostname or a recipient domain's MX host.
TCP checks for direct SMTP and authenticated relayBASH
# Direct delivery: use the recipient domain's MX host nc -vz -w 10 mx.example.net 25 # Authenticated relay: use its SMTP submission hostname nc -vz -w 10 smtp.example.net 587
These tests confirm TCP reachability. For a relay, also verify TLS negotiation and SMTP authentication. Microsoft's outbound SMTP guidance lists the subscription restrictions.
Set up SPF
Sender Policy Framework (SPF) checks the domain in SMTP MAIL FROM (the envelope sender), not the visible From header. For direct delivery, publish every static public outbound IPv4 address used by this mail route in the one SPF TXT record at the envelope domain. Azure NAT uses the public IP seen by receivers, so that is the address SPF must authorize.
SPF TXT record for direct deliveryDNS
example.com. 3600 IN TXT "v=spf1 ip4:203.0.113.10 -all"
- Inspect first: Look up the current TXT records at example.com. Never create a second SPF record.
- Merge the source: If SPF already exists, insert ip4:203.0.113.10 before its final all mechanism. Preserve every authorized sender already in use.
- Publish the TXT: In Azure DNS, open the authoritative public DNS zone and edit the existing @ TXT record set, or add it if absent. Paste the complete SPF value as one record and preserve unrelated TXT records.
- Match the return path: Set SMTP MAIL FROM to bounce@example.com or another address you control. If you use bounce.example.com, publish SPF there because SPF does not inherit from example.com.

SPF TXT record for an Azure VM in Azure DNS
For authenticated relay, use its exact SPF mechanism when it sends with an envelope domain you control. If the relay uses its own envelope domain, its operator manages that SPF record. Do not add the VM IP merely because the application runs there.
A relay that cannot use a return path under your domain will produce an SPF result that does not match the visible From domain. That does not break DMARC when an authorized DKIM signature uses your From domain and passes verification. Treat the SPF mismatch as expected for that route, then protect DKIM carefully.
SPF checker
Find SPF syntax issues, lookup limits, and weak records.
?/16tests passed
Run the SPF check against the envelope domain after DNS has propagated. Confirm there is one parsed SPF policy, the public sender is present, and no syntax error appears. The SPF DNS lookup limit is ten evaluated lookup-causing terms across the full recursive policy, including nested include and redirect terms. The ip4 and ip6 mechanisms do not consume that limit.
Use a hard fail ending (-all) once every legitimate source is authorized. During migration, keep the existing ending while testing so an omitted sender does not cause an avoidable SPF failure.
Set up DKIM
DomainKeys Identified Mail (DKIM) must be configured in the guest operating system or in the authenticated relay. Azure Virtual Machines does not sign messages. The Ubuntu and Postfix example below uses OpenDKIM, a 2048-bit RSA key, and selector azvm1. For another mail transfer agent, generate a key pair, publish the public key, and keep the private key on the signer.
- Install the signer: Install OpenDKIM and its key utility on the VM, then create a protected key directory.
- Generate the key: Create a 2048-bit key for example.com with selector azvm1. Keep azvm1.private readable only by the signing service.
- Publish the public key: Copy the complete TXT value from azvm1.txt into azvm1._domainkey at the DNS host. Join its quoted value segments; omit the record name, TXT keyword, and comments when pasting into the portal.
- Connect the milter: Point Postfix SMTP and non-SMTP mail through the local OpenDKIM socket, then restart both services.
- Confirm the domain: A delivered message must contain d=example.com and s=azvm1 in its DKIM-Signature header.
Save the signer settings in /etc/opendkim.conf and the trusted hosts in /etc/dkim/TrustedHosts. Replace conflicting Socket settings and disable any existing KeyTable or SigningTable settings for this single-domain example. The sample trusts local submission; add only specific trusted application IPs when needed, and configure Postfix relay permissions separately.
Install OpenDKIM and generate the keyBASH
sudo apt update sudo apt install opendkim opendkim-tools postfix sudo install -d -m 0700 -o opendkim -g opendkim /etc/dkim sudo opendkim-genkey -b 2048 -D /etc/dkim \ -d example.com -s azvm1 sudo chown opendkim:opendkim /etc/dkim/azvm1.private sudo chmod 0600 /etc/dkim/azvm1.private
Single-domain /etc/opendkim.conf configurationINI
UserID opendkim:opendkim Syslog yes Mode s Canonicalization relaxed/simple Domain example.com Selector azvm1 KeyFile /etc/dkim/azvm1.private Socket inet:8891@[127.0.0.1] InternalHosts refile:/etc/dkim/TrustedHosts
Trusted hosts and Postfix milter settingsINI
# /etc/dkim/TrustedHosts 127.0.0.1 localhost # /etc/postfix/main.cf milter_default_action = tempfail milter_protocol = 6 smtpd_milters = inet:127.0.0.1:8891 non_smtpd_milters = inet:127.0.0.1:8891

DKIM public key at azvm1._domainkey in Azure DNS
The Azure portal splits long TXT values into 255-character segments inside one record; do not create a separate TXT record for each segment. Paste the complete generated public value, including every character of p=, and never publish the private key. Verify the published key before restarting production traffic.
Verify the DKIM key before restartingBASH
sudo -u opendkim opendkim-testkey -d example.com -s azvm1 \ -k /etc/dkim/azvm1.private -vvv && sudo systemctl restart opendkim postfix
For key rotation, publish a new selector first, verify it, then switch signing. Retain the old public key until messages signed with it have cleared delivery queues and the DNS TTL has expired.
Windows VM and relay note
A Windows application or SMTP service without DKIM signing needs a DKIM-capable signing layer or authenticated relay. If the relay replaces the signature, publish its selector records and verify that its d= domain matches the visible From domain.
Set up DMARC
For a new deployment, confirm SPF and DKIM records resolve, then publish DMARC with p=none and aggregate reporting. If the domain already uses p=quarantine or p=reject, keep that policy and fix the Azure source without lowering enforcement.
Starting DMARC TXT recordDNS
_dmarc.example.com. 3600 IN TXT ( "v=DMARC1; p=none; rua=mailto:dmarc@example.com" )
- Set the host: Create a TXT record at _dmarc.example.com, represented by _dmarc when editing the example.com zone.
- Use monitoring mode: Publish the exact value v=DMARC1; p=none; rua=mailto:dmarc@example.com for a new deployment. Replace the report mailbox with one that can process aggregate XML.
- Retain enforcement: Do not move an existing quarantine or reject policy back to none. Correct the sender instead.
- Use relaxed matching: Keep the default relaxed SPF and DKIM domain matching unless a documented security requirement demands strict mode.
- Generate safely: Use our DMARC record generator when adding report addresses or advanced tags.

DMARC TXT record with p=none in Azure DNS
Domain-based Message Authentication, Reporting, and Conformance (DMARC) passes when at least one authentication path passes and its domain matches the visible From domain. For the direct Azure VM route, use bounce@example.com as the envelope sender for the SPF path and d=example.com in the DKIM signature for the DKIM path. The default relaxed mode permits matching organizational domains; aspf=s or adkim=s requires an exact domain match for that authentication path.
Aggregate reports usually arrive daily and expose the internet-facing source IP, volume, policy result, and authentication result. They do not prove inbox placement, so combine the report data with a real message test and the receiving server's Authentication-Results header. Microsoft's DMARC setup guidance also explains how SPF and DKIM results are checked against the visible From domain.
DMARC checker
Look up a domain's DMARC record and catch policy issues.
?/7tests passed
Check the exact visible From domain, including any sending subdomain, and confirm its effective DMARC policy. A subdomain without its own record inherits an applicable parent policy. Confirm one valid DMARC record at each queried name; a DNS check cannot prove the report mailbox accepts reports. Duplicate DMARC records at the same name invalidate that policy.
Keep the reporting mailbox active for the life of the record. A mailbox that rejects reports removes the evidence needed to find old applications, compromised credentials, or changes to the VM sending path. If rua points outside your organizational domain, confirm the reporting destination publishes the external-report authorization TXT record required by RFC 9990; follow the destination's supplied setup instructions.
Verify and troubleshoot
Verification needs both DNS checks and a real message. DNS proves that records can be found. A sent message proves that the outbound IP, envelope sender, signature, and visible From domain work together on the actual route.
- Query DNS: Resolve SPF, the azvm1 DKIM selector, DMARC, the A record, and the IP's PTR from a public resolver.
- Test the route: Send one message through the same application, VM, sender address, and connection mode used in production.
- Read the headers: Target spf=pass and dkim=pass for this configuration, plus dmarc=pass. DMARC itself needs only one passing authentication path whose domain matches header.from under the configured relaxed or strict mode.
- Check the egress IP: The received header must show the IP authorized by SPF for direct delivery, or the relay's IP for submission on port 587.
- Inspect VM logs: For Postfix, match the queue ID across application, Postfix, and OpenDKIM logs. A missing DKIM-Signature usually means the message bypassed the milter or used an untrusted source path.
Public DNS verificationBASH
dig +short A mail.example.com dig +short -x 203.0.113.10 dig +short TXT example.com dig +short TXT azvm1._domainkey.example.com dig +short TXT _dmarc.example.com
|
|
|
|---|---|---|
SPF | Pass with a domain matching From | IP or return path |
DKIM | Pass with a domain matching From | Signer or key |
DMARC | Pass | From domain |
PTR | Hostname resolving to the sending IP | Azure public IP |
SMTP | TCP 25 direct; TCP 587 relay | Route or policy |
Target results for this SPF and DKIM configuration
Send a controlled message through the production path after restarting the signing service and mail transfer agent. It catches selector mistakes, stale DNS, an unexpected return path, a relay that replaces DKIM, and outbound IP changes. Keep the full headers and VM queue ID while resolving failures.
Email tester
Send a real email to this address. Suped shows a results button when the test is ready.
?/43tests passed
Use the tester address as the recipient while preserving the production From address and envelope sender. Review the reported source IP, SPF domain, DKIM d= value, selector, and DMARC result as one transaction.
If direct delivery still times out, test TCP 25 before changing authentication records. A blocked connection is an Azure subscription or network path problem. SPF, DKIM, and DMARC cannot open the port.

Azure virtual network diagnostic for outbound SMTP port 25
Common failure map
- SPF fail or permerror: Check the observed sender IP and envelope domain, duplicate SPF records, syntax, and the ten-term lookup limit.
- DKIM none: The message bypassed the signer, or the signer did not recognize the sender as internal.
- DKIM fail: The public key is wrong, the selector is stale, or the message changed after signing.
- DMARC fail: Neither a passing SPF domain nor a passing DKIM domain matches the visible From domain.
- PTR missing: Set ReverseFqdn on the Azure public IPv4 resource after its forward A record resolves.
Monitor Azure VM email authentication
A working test message proves one moment in time. VM replacement, public IP reassignment, DKIM key rotation, application changes, DNS edits, or a relay configuration change can break authentication later. Continuous DMARC monitoring turns aggregate reports into source-level checks instead of leaving XML files in a mailbox.
Suped is our DMARC reporting and email authentication platform. Use our platform to identify Azure VM or relay sources, investigate authentication failures, and track domain authentication changes. Aggregate-report alerts depend on receiver reporting schedules. Use SMTP connection checks and VM logs for immediate transport failures.
- Verify the source: Label the expected Azure public IP or relay source so new infrastructure cannot hide in aggregate traffic.
- Alert on change: Notify the owner when SPF, DKIM, or DMARC failure volume crosses the configured threshold.
- Trace the cause: Separate an IP change, missing signature, wrong return path, and policy failure before editing DNS.
- Watch reputation: Monitor the direct-send IP and domain across major blocklists and blacklist data.
- Manage at scale: Use one multi-tenant dashboard for agencies, MSPs, subscriptions, and client domains.
Minimum production alert set
- New source: Alert when an unknown IP starts using the From domain.
- Failure spike: Alert when the normal authentication baseline changes sharply.
- Record change: Alert when SPF, DKIM, or DMARC DNS stops resolving as expected.
- Weekly review: Send a summary to the domain owner even when no urgent threshold fires.
Secure your domain with p=reject
Move to p=reject when every legitimate source has been identified and each important mail stream passes DMARC through SPF or DKIM. A high overall pass rate is not enough if a low-volume billing job or seasonal application still fails. Review sources by business owner and message type before enforcement.
DMARC enforcement gates
Advance only when the previous gate has no unexplained legitimate traffic.
Collect
p=none
Identify every source and owner.
Correct
Pass
Fix return paths, signatures, and keys.
Constrain
p=quarantine
Apply quarantine after reviewing legitimate sources.
Enforce
p=reject
Request rejection of messages that fail DMARC.
The pct tag is historic under RFC 9989. Do not use it for percentage-based rollout. Where practical, stage policy changes on verified sending subdomains and confirm their effective DMARC policies. Receivers apply the published policy according to their implementations and local handling rules.
- Inventory by source: Map every IP and DKIM domain in aggregate reports to an application owner. Include low-volume and seasonal traffic.
- Fix before filtering: Correct the Azure IP, envelope sender, selector, public key, or signing path while reviewing aggregate reports. Preserve any existing enforcement policy.
- Stage quarantine: Move to p=quarantine after verifying legitimate sources, then watch for legitimate failures across a full sending cycle.
- Publish reject: Set p=reject after every owner approves the source inventory and test results.
- Keep monitoring: Continue source alerts and weekly review after enforcement because infrastructure and DNS still change.
Final DMARC TXT recordDNS
_dmarc.example.com. 3600 IN TXT ( "v=DMARC1; p=reject; rua=mailto:dmarc@example.com" )
Suped's Hosted DMARC workflow handles policy staging without repeated DNS edits. Use received report data to find remaining source failures, then review subsequent reports for regressions after each policy change.
Do not enforce on a pass rate alone
A 99% pass rate can hide a critical source that sends only once a month. Require a named owner for every legitimate source, a passing production test, and enough report history to include infrequent mail before publishing p=reject.
Frequently asked questions
No. Azure provides compute, networking, public IP, and DNS capabilities. The domain owner publishes SPF and DMARC, while the mail transfer agent or authenticated relay signs DKIM.
That suffix identifies a DNS name label on a Microsoft Azure public IP resource. Azure creates no default PTR. The suffix appears in reverse DNS only when the public IP owner explicitly sets that Azure hostname as ReverseFqdn. A custom mail.example.com PTR is usually clearer for direct email.
If the relay uses an envelope domain it owns, its operator publishes SPF there. Add the relay's required SPF mechanism only for a custom envelope domain you control. DMARC passes through DKIM when the signature verifies and its d= domain matches From under the configured matching mode. For direct delivery, configure your own envelope sender in the application or mail transfer agent.
Azure blocks outbound port 25 for most subscription types. Standard EA and MCA-E subscriptions can use direct SMTP. Eligible Enterprise Dev/Test subscriptions can request an exemption. Other subscriptions need authenticated submission on port 587.
Yes. SPF can pass for a relay-owned envelope domain while the visible From address uses your domain. DMARC needs a passing SPF or DKIM domain that matches the From domain under the selected relaxed or strict mode.
It is ready after every legitimate direct-send IP or relay has an owner, production tests pass, aggregate reports show no unexplained legitimate failures, and the review period includes infrequent sending jobs.

