SPF problem when forwarding emails

Forwarding emails can be a problem when the SPF (Sender Policy Framework) entry of the sender’s domain is set to “-all”. SPF is an email validation system designed to prevent spam and phishing by verifying that an incoming message was sent from an authorized server.

When an SPF record is set to “-all”, it indicates that no other servers are authorized to send email on behalf of the domain. This means that if an email is forwarded from an unauthorized server to another server, the receiving server may reject the message as a potential spam or phishing attempt.

E.g. if someone sends you an email from example.com and you want to automatically forward your emails from your domain myemailaddress.com to e.g. your GMail account, then this won’t work, because GMail won’t accept the email, because myemailaddress.com is not allowed to send “@example.com” emails. Only the mailservers of example.com are allowed to send such emails.

A solution can be to use an IMAP forwarder, i.e. a program that connects to both IMAP servers (myemailaddress.com and GMail in that example) and automatically sends all emails that appear on myemailaddress.com to GMail).

A free open source solution is the project IMAPTransfer on GitHub.

It is written in Kotlin and can watch the source server for changes and immediately write these new emails into the target IMAP server. Or it can write the new emails (or all emails to create a backup or an archive) into local .eml files . It can even restore these .eml files into another IMAP server.