Django重置使用DomainKey与Amazon SES签名的密码电子邮件

时间:2022-10-24 19:21:31

The application I am trying to experiment allows users to reset their password using djangos inbuilt PasswordResetForm , currently I am overriding it to be able to send HTML emails using EmailMultiAlternatives.

我试图实验的应用程序允许用户使用内置的PasswordResetForm重置密码,目前我正在重写它以便能够使用EmailMultiAlternatives发送HTML电子邮件。

How it currently looks and works fine.

它目前的外观和工作原理。

c ={'name':'Shabeer'}
subject = 'Test Amazon SES'
txt_content = loader.render_to_string('registration/password_reset_email.txt', c)
html_content = loader.render_to_string(email_template_name, c)

msg = EmailMultiAlternatives(subject, txt_content, from_email, [user.email]);            
msg.attach_alternative(html_content, 'text/html')
msg.send()

So now I started with the help of this Getting started example by hmarr,here is the code I added to my settings.py

所以现在我从hmarr的这个入门示例的帮助开始,这是我添加到settings.py中的代码

EMAIL_BACKEND = 'django_ses.SESBackend'

DEFAULT_FROM_EMAIL = 'shabeer@sheffa.com'

AWS_ACCESS_KEY_ID = 'MyAcCeSsKeYiD'
AWS_SECRET_ACCESS_KEY = 'MySeCrEtAcCeSsKeY'
AWS_SES_REGION_NAME = 'us-east-1'
AWS_SES_REGION_ENDPOINT = 'email.us-east-1.amazonaws.com'
AWS_SES_RETURN_PATH = 'shabeer@sheffa.com'

And the emails get successfully sent to users via amazon SES.

电子邮件通过亚马逊SES成功发送给用户。


So now here is my problem.

所以现在这是我的问题。

I am trying to avoid seeing "via" followed by a domain name next to the sender's name.

我试图避免看到“via”后面跟着发件人姓名旁边的域名。

To achieve that I started to follow the next step DKIM of the guide. :

为了达到这个目的,我开始按照指南的下一步DKIM进行操作。 :

  1. Added the DKIM settings for my domain that was generated by Amazon SES
  2. 添加了由Amazon SES生成的域的DKIM设置

  3. Added the following to settings.py
  4. 在settings.py中添加了以下内容

DKIM_DOMAIN = 'myDomainName.com'`

DKIM_DOMAIN ='myDomainName.com'

  1. Downloaded openssl-for windows , and followed the commands

    下载openssl-for windows,然后按照命令操作

    • openssl genrsa -out myDomainName.com.key 512
    • openssl genrsa -out myDomainName.com.key 512

    • openssl rsa -in myDomainName.com.key -out rsa.public -pubout -outform PEM

      Two files got created : myDomainName.com.key and rsa.public
    • openssl rsa -in myDomainName.com.key -out rsa.public -poutout -outform PEM创建了两个文件:myDomainName.com.key和rsa.public

  2. Added the DKIM_PRIVATE_KEY to settings.py

    将DKIM_PRIVATE_KEY添加到settings.py

    DKIM_PRIVATE_KEY = ''' xxxxxxxxxxxxxxxxxxxxxxxxxx
    MY Long Private Key
    xxxxxxxxxxxxxxxxxxxxxxxxxx
    '''

    DKIM_PRIVATE_KEY ='''xxxxxxxxxxxxxxxxxxxxxxxxxx我的长私钥xxxxxxxxxxxxxxxxxxxxxxxxxx'''

  3. Added the DNS Entry

    添加了DNS条目

    ses._domainkey.myDomainName.com TXT '"v=DKIM1; p=myPublicKey"'

    ses._domainkey.myDomainName.com TXT'“v = DKIM1; p = myPublicKey”'

With all the above done, I run my project and try to reset my password, and this error gets thrown :

完成上述所有操作后,我运行我的项目并尝试重置密码,并抛出此错误:

Exception Type: KeyFormatError at /password_reset/
Exception Value: Private key not found

I trying to understand what I have missed or gone wrong, some advice/assistance on how I could solve this would be really help full.

我试图了解我错过了什么或出错了,关于如何解决这个问题的一些建议/帮助真的很有帮助。

I am a rookie at Django/Python so please bear with me.

我是Django / Python的新手,所以请耐心等待。

Thanks you in advance.

提前谢谢你。

UPDATE 28 Oct 2013:

2013年10月28日更新:

I am still trying to figure out which Private Key django is looking for while I have already added DKIM_PRIVATE_KEY in my settings.py

我仍在尝试找出哪个私钥django正在寻找,而我已经在settings.py中添加了DKIM_PRIVATE_KEY


UPDATE 29 Oct 2013:

更新2013年10月29日:

  • With the help of Paul Egan I updated my DKIM_PRIVATE_KEY in my settings.py to include PEM header looks like this now :

    在Paul Egan的帮助下,我在settings.py中更新了我的DKIM_PRIVATE_KEY以包含PEM标题,如下所示:

    DKIM_PRIVATE_KEY = '''
    -----BEGIN RSA PRIVATE KEY-----
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    -----END RSA PRIVATE KEY----- '''

    DKIM_PRIVATE_KEY = '' '----- BEGIN RSA私钥----- xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ----- END RSA私钥----- '''

The emails get sent now without any errors, but the email I receive still shows via amazonses.com

电子邮件现在发送没有任何错误,但我收到的电子邮件仍然通过amazonses.com显示

1 个解决方案

#1


1  

The Private key not found error is thrown from parse_pem_private_key. This suggests that your setting doesn't include the PEM headers. Double check that it looks something like:

从parse_pem_private_key抛出未找到私钥错误。这表明您的设置不包含PEM标头。仔细检查它看起来像:

DKIM_PRIVATE_KEY = '''
-----BEGIN RSA PRIVATE KEY-----
xxxxxxxxxxx
-----END RSA PRIVATE KEY-----
'''

There's another option you might also want to consider. Last year AWS added support for adding the DKIM signature on their side: http://docs.aws.amazon.com/ses/latest/DeveloperGuide/easy-dkim.html. You might find this easier to configure and it has the added advantage of keeping the private key away from your source code.

您可能还需要考虑另一种选择。去年,AWS增加了对添加DKIM签名的支持:http://docs.aws.amazon.com/ses/latest/DeveloperGuide/easy-dkim.html。您可能会发现这更容易配置,并且它具有使私钥远离源代码的附加优势。

#1


1  

The Private key not found error is thrown from parse_pem_private_key. This suggests that your setting doesn't include the PEM headers. Double check that it looks something like:

从parse_pem_private_key抛出未找到私钥错误。这表明您的设置不包含PEM标头。仔细检查它看起来像:

DKIM_PRIVATE_KEY = '''
-----BEGIN RSA PRIVATE KEY-----
xxxxxxxxxxx
-----END RSA PRIVATE KEY-----
'''

There's another option you might also want to consider. Last year AWS added support for adding the DKIM signature on their side: http://docs.aws.amazon.com/ses/latest/DeveloperGuide/easy-dkim.html. You might find this easier to configure and it has the added advantage of keeping the private key away from your source code.

您可能还需要考虑另一种选择。去年,AWS增加了对添加DKIM签名的支持:http://docs.aws.amazon.com/ses/latest/DeveloperGuide/easy-dkim.html。您可能会发现这更容易配置,并且它具有使私钥远离源代码的附加优势。