How can I use E-Mailrelay to implement DKIM?

tr flag

I am trying to add DKIM to an existing windows server which is currently using IIS SMTP for outgoing mail.

It seems like this could be done by using E-Mailrelay. Unfortunately I could not find any reference on how exactly to configure DKIM in E-Mailrelay.

Is there something I missed in the docs or perhaps some third party tutorial that describes how to do this?

djdomi avatar
za flag
did you add the ips to the SPF records?
tr flag
Yes, but how is this related to my question?
tr flag

I implemented a simple command line app with C# / NET 6 to act as a filter in E-MailRelay:

using System.IO;
using System.Text;
using MimeKit;
using MimeKit.Cryptography;

namespace E_MailRelay.DKIM.Filter;

/// <summary>
/// Reads an e-mail message, adds a Hardcoded DKIM signature and and writes 
the updated message back to disk
/// Note that this requires the installation MailKit to work. 
/// </summary>

internal class Program
private const string DKIMSelector = "ENTER_YOUR_DKIM_SELECTOR_HERE";
private const string _DKIMDomain = "ENTER_YOUR_DOMAIN_NAME_HERE";
private const string DKIMPrivateKey = "-----BEGIN RSA PRIVATE KEY-----\r\n"
                                      + @"ENTER_YOUR_PRIVATE_KEY_HERE"
                                      + "\r\n-----END RSA PRIVATE KEY-----";

private static int Main(string[] args)
    return 102;

private static void LoadSignAndRewriteMail(string[] args)
    var emailMessage = MimeMessage.Load(args[0]);
    if (!emailMessage.Headers.Contains(HeaderId.DkimSignature)
        && !emailMessage.Headers.Contains(HeaderId.DomainKeySignature))


private static void SignMail(MimeMessage emailMessage)
    var pk = DKIMPrivateKey;
    MemoryStream stream = new(Encoding.UTF8.GetBytes(pk));
        stream.Position = 0;

    var dkimSigner = new DkimSigner(stream, _DKIMDomain, DKIMSelector);

    HeaderId[] dkimSignHeaders =
        HeaderId.To, HeaderId.Cc, HeaderId.Subject, HeaderId.From, HeaderId.Date, HeaderId.MessageId, HeaderId.Body,
        HeaderId.Date, HeaderId.MimeVersion, HeaderId.Sender, HeaderId.ReplyTo, HeaderId.ContentTransferEncoding,
        HeaderId.ContentId, HeaderId.ContentDescription, HeaderId.ResentDate, HeaderId.ResentFrom,
        HeaderId.ResentSender, HeaderId.ResentTo, HeaderId.ResentCc, HeaderId.ResentMessageId, HeaderId.InReplyTo,

    dkimSigner.Sign(FormatOptions.Default, emailMessage, dkimSignHeaders);

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.