Double Dkim Setup

kumo.on(‘smtp_server_message_received’, function(msg)
–local signer0 = kumo.dkim.rsa_sha256_signer {
–domain = msg:from_header().domain,
domain_gmail = msg:to_header().domain,
–selector = ‘acls01’,
headers = {‘Content-Type’, ‘Message-Id’, ‘Subject’, ‘Date’, ‘Mime-Version’, ‘To’, ‘From’},
–key = ‘/opt/kumomta/etc/dkim/acl.pinchappmails.com/acls01.key’,
–}
if (domain_gmail == ‘gmail’)
then
local signer2 = kumo.dkim.rsa_sha256_signer {
domain = msg:from_header().domain,
–domain = msg:to_header().domain,
selector = ‘acls01’,
headers = {‘Content-Type’, ‘Message-Id’, ‘Subject’, ‘Date’, ‘Mime-Version’, ‘To’, ‘From’},
key = ‘/opt/kumomta/etc/dkim/acl.pinchappmails.com/acls01.key’,
}
local signer1 = kumo.dkim.rsa_sha256_signer {
domain = ‘aclmobile.net’,
selector = ‘5nXKKHgBnyGAcLwvMLZIq’,
headers = {‘Content-Type’, ‘Message-Id’, ‘Subject’, ‘Date’, ‘Mime-Version’, ‘To’, ‘From’},
key = ‘/opt/kumomta/etc/dkim/aclmobile.net/5nXKKHgBnyGAcLwvMLZIq.key’,
}
msg:dkim_sign(signer1)
msg:dkim_sign(signer2)
else
local signer3 = kumo.dkim.rsa_sha256_signer {
domain = msg:from_header().domain,
selector = ‘acls01’,
headers = {‘Content-Type’, ‘Message-Id’, ‘Subject’, ‘Date’, ‘Mime-Version’, ‘To’, ‘From’},
key = ‘/opt/kumomta/etc/dkim/acl.pinchappmails.com/acls01.key’,
}
msg:dkim_sign(signer3)

end
end)

The domain will have an extension, it won’t be just “gmail”

even though I have put the extension the result is same

Gmail has a lot of extensions, you’d probably be better using string.find instead of equality.

as a tip, when pasting lua code in here you can enclose it in a markdown style fenced code block to have it format and syntax highlight it, as shown in this screenshot. It will render like this:

kumo.on('smtp_server_message_received', function(msg)
--local signer0 = kumo.dkim.rsa_sha256_signer {

ok thanks wez

I tried with thestr.find function but I am getting error 421

Please make a habit of showing your code and errors to help us help you.

ok

Escape character is ‘^]’.
220 Mailhub KumoMTA
ehlo mail.com
250-Mailhub Aloha mail.com
250-PIPELINING
250-ENHANCEDSTATUSCODES
250 STARTTLS
mail from:test@comm.pinchappmails.com
250 OK EnvelopeAddress(“test@comm.pinchappmails.com”)
rcpt to:anshukla60@gmail.com
250 OK EnvelopeAddress(“aa@gmail.com”)
DATA
354 Send body; end with CRLF.CRLF
From:test@acl.pinchappmails.com
To:ashutosh.shukla@sinch.com
Subject:Test

test email.

.
421 4.3.0 Mailhub technical difficulties
Connection closed by foreign host.

And your code?

kumo.on('smtp_server_message_received', function(msg)
local signer0 = kumo.dkim.rsa_sha256_signer {
    --domain = msg:from_header().domain,
   domain = msg:to_header().domain,
    selector = '00',
    headers = {'Content-Type', 'Message-Id', 'Subject', 'Date', 'Mime-Version', 'To', 'From'},
    key = '/opt/kumomta/etc/dkim/acl.pinchappmails.com/00.key',
  }
  --if (dom == 'gmail.com')
          --then
                local signer2 = kumo.dkim.rsa_sha256_signer {
                domain = msg:from_header().domain,
                --domain = msg:to_header().domain,
                selector = 'acls01',
                headers = {'Content-Type', 'Message-Id', 'Subject', 'Date', 'Mime-Version', 'To', 'From'},
                key = '/opt/kumomta/etc/dkim/acl.pinchappmails.com/acls01.key',
                                }
                local signer1 = kumo.dkim.rsa_sha256_signer {
                domain = 'aclmobile.net',
                selector = '5nXKKHgBnyGAcLwvMLZIq',
                headers = {'Content-Type', 'Message-Id', 'Subject', 'Date', 'Mime-Version', 'To', 'From'},
                key = '/opt/kumomta/etc/dkim/aclmobile.net/5nXKKHgBnyGAcLwvMLZIq.key',
                                }
 --[[            msg:dkim_sign(signer1)
                msg:dkim_sign(signer2)
  else
          local signer3 = kumo.dkim.rsa_sha256_signer {
                domain = msg:from_header().domain,
                selector = 'acls01',
                headers = {'Content-Type', 'Message-Id', 'Subject', 'Date', 'Mime-Version', 'To', 'From'},
                key = '/opt/kumomta/etc/dkim/acl.pinchappmails.com/acls01.key',
                                }
                msg:dkim_sign(signer3)

  end]]
  if str.find(domain, 'gmail.com')
          then
                  msg:dkim_sign(signer1)
                msg:dkim_sign(signer2)
      else
                msg:dkim_sign(signer2)
   end
end)```

when you see 421 ... technical difficulties you can usually see a lua stack trace in the journal. Troubleshooting KumoMTA - KumoMTA Docs has information on how to review the journal

thanks @free-spirited-yorksh it’s helping me a lot to rectify the error, thanks

 
kumo.on('smtp_server_message_received', function(msg)
local signer0 = kumo.dkim.rsa_sha256_signer {
    --domain = msg:from_header().domain,
   domain= msg:to_header().domain,
    selector = 'aace01',
    headers = { 'From','To'},
    key = '/opt/kumomta/etc/dkim/aace.com/aace01.key',
  }
  if (domain == "gmail.com")
          then
                local signer2 = kumo.dkim.rsa_sha256_signer {
                domain = msg:from_header().domain,
                --domain = msg:to_header().domain,
                selector = 'acls01',
                headers = {'Content-Type', 'Message-Id', 'Subject', 'Date', 'Mime-Version', 'To', 'From'},
                key = '/opt/kumomta/etc/dkim/acl.pinchappmails.com/acls01.key',
                                }
                local signer1 = kumo.dkim.rsa_sha256_signer {
                domain = 'aclmobile.net',
                selector = '5nXKKHgBnyGAcLwvMLZIq',
                headers = {'Content-Type', 'Message-Id', 'Subject', 'Date', 'Mime-Version', 'To', 'From'},
                key = '/opt/kumomta/etc/dkim/aclmobile.net/5nXKKHgBnyGAcLwvMLZIq.key',
                                }
                msg:dkim_sign(signer1)
                msg:dkim_sign(signer2)
        else
                local signer3 = kumo.dkim.rsa_sha256_signer {
                domain = msg:from_header().domain,
                selector = 'aace01',
                headers = {'Content-Type', 'Message-Id', 'Subject', 'Date', 'Mime-Version', 'To', 'From'},
                key = '/opt/kumomta/etc/dkim/aace.com/aace01.key',
                                }
                msg:dkim_sign(signer3)
   end
end)

I tried this but only one header is signing the domain and the else block is calling not the if block

Print your domain and check the logs to see if it is what you expect.

if (domain == "gmail.com") references the local variable domain, but that isn’t set to anything.

You need to add a line like this before your if block:

local domain = msg:recipient().domain

or just make your if block reference it directly:

if msg:recipient().domain == "gmail.com" then

Keeping in mind that there’s a lot of international Gmail TLDs, so specifying gmail.com may be limiting.