slimta / python-slimta

Python libraries to send, receive, and queue email.
https://slimta.org/
MIT License
171 stars 43 forks source link

DKIM #21

Open rgcarrasqueira opened 10 years ago

rgcarrasqueira commented 10 years ago

Hi Ian,

Is there in the pipeline a slimta's version with DKIM support?

Thanks so much!

icgood commented 10 years ago

There should be! I haven't had need for it yet, but the dkimpy project appears to be perfect for the job. It probably won't take long to add.

rgcarrasqueira commented 10 years ago

Hi Ian,

I've tried to use DKIM, it signs the message but I'm having problem to sign correctly the message. I've created an Edge that write and sign my email messages there but, the always appear a error about messagen content changed and the sign fails. There is correctly place (Edge, StaticRelay or other..) to put the message to sign and send it correctly?

Thanks so much!

Rogério Carrasqueira

blackrosezy commented 10 years ago

hi rgcarrasqueira,

Why do you close this issue? Do you manage to solve it?

rgcarrasqueira commented 10 years ago

Yes We solved! Thanks

Rogério Carrasqueira


e-mail: rogerio.carrasqueira@gmail.com skype: rgcarrasqueira MSN: rcarrasqueira@hotmail.com twitter: @carrasqueira Tel.: (11) 95708-0074 PMI Member ID: 2329374

2014-07-14 23:24 GMT-03:00 Mohd Rozi notifications@github.com:

hi rgcarrasqueira,

Why do you close this issue? Do you manage to solve it?

— Reply to this email directly or view it on GitHub https://github.com/slimta/python-slimta/issues/21#issuecomment-48983494.

reikjarloekl commented 9 years ago

hi rgcarrasqueira,

could you elaborate on how you managed to get it to work? I am looking at the same problem right now.

thanks and best regards,

Jörn

zombified commented 5 months ago

no relation to the original poster or other solutions, but for reference, the things that are needed to get dkim integrated in a custom deployment would be:

  1. creating a subclass of slimta.policy.RelayPolicy and writing an "apply" method that uses dkimpy to generate the signing header based on the info in the given envelop, and then appends the signature to the envelope
  2. add the policy to the relay object being used (eg slimta.relay.smtp.mx.MxSmtpRelay or some subclass of it)

it should only be ~120 lines of code at most for the specific needs of dkim, and that's pretty generous

the core of the custom policy is going to be something like this (example, non-functional):

header_data, message_data = env.flatten()
rfc822msg = "{}{}".format(header_data.decode(), message_data.decode())

# defaults for the dkimpy library
ident = None
canon = (b'relaxed', b'relaxed')
algo = b'rsa-sha256'
length = False

sig = sign(rfc822msg.encode(),
    selector.encode(),
    domain.encode(),
    privkey.encode(),
    identity=ident,
    canonicalize=canon,
    signature_algorithm=algo,
    include_headers=headers,
    length=length,
    logger=logger)
sigd = sig.decode()[16:].rstrip()
# there really should just be one dkim signing header
del env.headers['DKIM-Signature']
env.prepend_header("DKIM-Signature", sigd)