<i id='d0wJ6'><tr id='d0wJ6'><dt id='d0wJ6'><q id='d0wJ6'><span id='d0wJ6'><b id='d0wJ6'><form id='d0wJ6'><ins id='d0wJ6'></ins><ul id='d0wJ6'></ul><sub id='d0wJ6'></sub></form><legend id='d0wJ6'></legend><bdo id='d0wJ6'><pre id='d0wJ6'><center id='d0wJ6'></center></pre></bdo></b><th id='d0wJ6'></th></span></q></dt></tr></i><div id='d0wJ6'><tfoot id='d0wJ6'></tfoot><dl id='d0wJ6'><fieldset id='d0wJ6'></fieldset></dl></div>

  • <small id='d0wJ6'></small><noframes id='d0wJ6'>

    <tfoot id='d0wJ6'></tfoot>

      • <bdo id='d0wJ6'></bdo><ul id='d0wJ6'></ul>
      <legend id='d0wJ6'><style id='d0wJ6'><dir id='d0wJ6'><q id='d0wJ6'></q></dir></style></legend>
      1. 错误:SMTPRecipientsRefused 553, '5.7.1 #while 在 django 中处理

        时间:2023-07-02
        <legend id='0eELx'><style id='0eELx'><dir id='0eELx'><q id='0eELx'></q></dir></style></legend>

          <tbody id='0eELx'></tbody>

            <small id='0eELx'></small><noframes id='0eELx'>

            <i id='0eELx'><tr id='0eELx'><dt id='0eELx'><q id='0eELx'><span id='0eELx'><b id='0eELx'><form id='0eELx'><ins id='0eELx'></ins><ul id='0eELx'></ul><sub id='0eELx'></sub></form><legend id='0eELx'></legend><bdo id='0eELx'><pre id='0eELx'><center id='0eELx'></center></pre></bdo></b><th id='0eELx'></th></span></q></dt></tr></i><div id='0eELx'><tfoot id='0eELx'></tfoot><dl id='0eELx'><fieldset id='0eELx'></fieldset></dl></div>
          1. <tfoot id='0eELx'></tfoot>
                  <bdo id='0eELx'></bdo><ul id='0eELx'></ul>

                  本文介绍了错误:SMTPRecipientsRefused 553, '5.7.1 #while 在 django 中处理联系表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在 django 1.3、python 2.6 中创建联系表单.

                  出现以下错误的原因是什么?

                  错误:

                  SMTPRecipientsRefused at/contact/{'test@test.megiteam.pl': (553, '5.7.1 <randomacc@hotmail.com>: 发件人地址拒绝:不属于用户 test@test.megiteam.pl')}

                  我的设置.py:

                  EMAIL_HOST = 'test.megiteam.pl'EMAIL_HOST_USER = 'test@test.megiteam.pl'EMAIL_HOST_PASSWORD = '###'DEFAULT_FROM_EMAIL = 'test@test.megiteam.pl'SERVER_EMAIL = 'test@test.megiteam.pl'EMAIL_USE_TLS = 真

                  如果任何其他人关注 djangobook,这就是导致它的部分:

                   send_mail(request.POST['主题'],request.POST['message'],request.POST.get('email', 'noreply@example.com'), #摆脱'email'['siteowner@example.com'],

                  解决方案

                  解释在错误信息中.由于您从联系表单中获取的发件人地址 randomcc@hotmail.com,您的电子邮件主机拒绝了该电子邮件.

                  相反,您应该使用自己的电子邮件地址作为发件人地址.您可以使用 reply_to 选项将回复发送给您的用户.

                  email = EmailMessage('主题','身体在这里','test@test.megiteam.pl',['to@example.com',],reply_to='randomcc@hotmail.com',)电子邮件.send()

                  在 Django 1.7 及更早版本上,没有 reply_to 参数,但您可以手动设置 Reply-To 标头:

                  email = EmailMessage('主题','身体在这里','test@test.megiteam.pl',['to@example.com',],headers = {'Reply-To': 'randomacc@hotmail.com'},)电子邮件.send()

                  在评论中,您询问了如何在邮件正文中包含发件人的地址.messagefrom_email 只是字符串,因此您可以在发送电子邮件之前随意组合它们.

                  请注意,您不应从 clean_data 中获取 from_email 参数.你知道 from_address 应该是 test@test.megiteam.pl,所以使用它,或者从你的设置中导入 DEFAULT_FROM_EMAIL.p>

                  请注意,如果您像上面的示例一样使用 EmailMessage 创建消息,并将回复设置为标题,那么当您点击回复按钮时,您的电子邮件客户端应该会做正确的事情.下面的示例使用 send_mail 使其与 您链接到的代码相似..p>

                  从 django.conf 导入设置...如果 form.is_valid():cd = form.cleaned_data消息 = cd['消息']# 从表单的清理数据构造消息体正文 = """发件人:%s消息:%s""" % (cd['email'], cd['message'])发送邮件(cd['主题'],身体,settings.DEFAULT_FROM_EMAIL, # 使用您的电子邮件地址,而不是表单中的那个['test@test.megiteam.pl'],)

                  im trying to make a contact form in django 1.3, python 2.6.

                  Whats the reason of following error?

                  error:

                  SMTPRecipientsRefused at /contact/
                  {'test@test.megiteam.pl': (553, '5.7.1 <randomacc@hotmail.com>: Sender address
                  rejected: not owned by user test@test.megiteam.pl')}
                  

                  my settings.py:

                  EMAIL_HOST = 'test.megiteam.pl'
                  EMAIL_HOST_USER = 'test@test.megiteam.pl'
                  EMAIL_HOST_PASSWORD = '###' 
                  DEFAULT_FROM_EMAIL = 'test@test.megiteam.pl'
                  SERVER_EMAIL = 'test@test.megiteam.pl'
                  EMAIL_USE_TLS = True
                  

                  edit: If any1 else was following djangobook, this is the part causing it:

                          send_mail(
                              request.POST['subject'],
                              request.POST['message'],
                              request.POST.get('email', 'noreply@example.com'), #get rid of 'email'
                              ['siteowner@example.com'],
                  

                  解决方案

                  The explanation is in the error message. Your email host is rejecting the email because of the sender address randomacc@hotmail.com that you have taken from the contact form.

                  Instead, you should use your own email address as the sender address. You can use the reply_to option so that replies go to your user.

                  email = EmailMessage(
                      'Subject',
                      'Body goes here',
                      'test@test.megiteam.pl',
                      ['to@example.com',],
                      reply_to='randomacc@hotmail.com',
                  )
                  email.send()
                  

                  On Django 1.7 and earlier, there isn't a reply_to argument, but you can manually set a Reply-To header:

                  email = EmailMessage(
                      'Subject',
                      'Body goes here',
                      'test@test.megiteam.pl',
                      ['to@example.com',],
                      headers = {'Reply-To': 'randomacc@hotmail.com'},
                  )
                  email.send()
                  

                  Edit:

                  In the comments you asked how to include the sender's address in the message body. The message and from_email are just strings, so you can combine them however you want before you send the email.

                  Note that you shouldn't get the from_email argument from your cleaned_data. You know that the from_address should be test@test.megiteam.pl, so use that, or maybe import DEFAULT_FROM_EMAIL from your settings.

                  Note that if you create a message using EmailMessage as in my example above, and set the reply to header, then your email client should do the right thing when you hit the reply button. The example below uses send_mail to keep it similar to the code you linked to.

                  from django.conf import settings
                  
                  ...
                      if form.is_valid():
                          cd = form.cleaned_data
                          message = cd['message']
                          # construct the message body from the form's cleaned data
                          body = """
                  from: %s
                  message: %s""" % (cd['email'], cd['message'])
                          send_mail(
                              cd['subject'],
                              body,
                              settings.DEFAULT_FROM_EMAIL, # use your email address, not the one from the form
                              ['test@test.megiteam.pl'],
                          )
                  

                  这篇关于错误:SMTPRecipientsRefused 553, '5.7.1 #while 在 django 中处理联系表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在没有身份验证的情况下直接向 SMTP 服务器发送邮件? 下一篇:一个简单的 SMTP 服务器(在 Python 中)

                  相关文章

                • <small id='lWAxD'></small><noframes id='lWAxD'>

                    • <bdo id='lWAxD'></bdo><ul id='lWAxD'></ul>

                    <legend id='lWAxD'><style id='lWAxD'><dir id='lWAxD'><q id='lWAxD'></q></dir></style></legend>

                      <tfoot id='lWAxD'></tfoot>
                      <i id='lWAxD'><tr id='lWAxD'><dt id='lWAxD'><q id='lWAxD'><span id='lWAxD'><b id='lWAxD'><form id='lWAxD'><ins id='lWAxD'></ins><ul id='lWAxD'></ul><sub id='lWAxD'></sub></form><legend id='lWAxD'></legend><bdo id='lWAxD'><pre id='lWAxD'><center id='lWAxD'></center></pre></bdo></b><th id='lWAxD'></th></span></q></dt></tr></i><div id='lWAxD'><tfoot id='lWAxD'></tfoot><dl id='lWAxD'><fieldset id='lWAxD'></fieldset></dl></div>