我无法使用django.core.mail.send_mail函数发送电子邮件。
使用mail_admins和mail_managers发送邮件工作正常,所以我猜问题不是我的邮件配置。
我在
中收到“不正确的填充”错误File "/usr/lib/python2.6/base64.py" in decodestring
321. return binascii.a2b_base64(s)
这也很奇怪,因为我的django服务器在virtualenv中运行。 完整的追溯如下:
Traceback:
File "/env_frugar/lib/python2.6/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/env/lib/python2.6/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
23. return view_func(request, *args, **kwargs)
File "/env/lib/python2.6/site-packages/django/views/generic/base.py" in view
47. return self.dispatch(request, *args, **kwargs)
File "/env/lib/python2.6/site-packages/django/views/generic/base.py" in dispatch
68. return handler(request, *args, **kwargs)
File "/env/lib/python2.6/site-packages/django/views/generic/edit.py" in post
172. return super(BaseCreateView, self).post(request, *args, **kwargs)
File "/env/lib/python2.6/site-packages/django/views/generic/edit.py" in post
138. return self.form_valid(form)
File "/env/lib/python2.6/site-packages/django/views/generic/edit.py" in form_valid
112. self.object = form.save()
File "/env/lib/python2.6/site-packages/django/forms/models.py" in save
363. fail_message, commit, construct=False)
File "/env/lib/python2.6/site-packages/django/forms/models.py" in save_instance
85. instance.save()
File "/env/lib/python2.6/site-packages/django/db/models/base.py" in save
460. self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/env/lib/python2.6/site-packages/django/db/models/base.py" in save_base
570. created=(not record_exists), raw=raw, using=using)
File "/env/lib/python2.6/site-packages/django/dispatch/dispatcher.py" in send
172. response = receiver(signal=self, sender=sender, **named)
File "/myproject/myapp/models.py" in send_email_after_widget_creation
88. send_mail(subject, message, from_email, recipient_list, fail_silently= not settings.DEBUG)
File "/env/lib/python2.6/site-packages/django/core/mail/__init__.py" in send_mail
61. connection=connection).send()
File "/env/lib/python2.6/site-packages/django/core/mail/message.py" in send
251. return self.get_connection(fail_silently).send_messages([self])
File "/env/lib/python2.6/site-packages/django/core/mail/backends/smtp.py" in send_messages
79. new_conn_created = self.open()
File "/env/lib/python2.6/site-packages/django/core/mail/backends/smtp.py" in open
48. self.connection.login(self.username, self.password)
File "/usr/lib/python2.6/smtplib.py" in login
574. (code, resp) = self.docmd(encode_cram_md5(resp, user, password))
File "/usr/lib/python2.6/smtplib.py" in encode_cram_md5
537. challenge = base64.decodestring(challenge)
File "/usr/lib/python2.6/base64.py" in decodestring
321. return binascii.a2b_base64(s)
关于可能发生的事情的任何想法?
UPADTE:
主题是(它是葡萄牙语):
身体是:
[Django] [FRUGAR-WiDGET] novo widget criado
Novo widget criado: Nome:test 10 Por: dudu
答案 0 :(得分:0)
Base-64将3个字节(0-255范围内的回声)编码为4个字节(每个字节位于a 更受限制的范围)。输出的长度总是一个倍数 4(忽略空白);该方法添加额外的填充字节(ASCII ' =')确保如果输入的长度不是这样的话 3的倍数。
因此,如果解码会引发"不正确的填充"错误然后剥离任何 空格并附加额外的ASCII' ='使其长度成为的倍数 3,然后再次尝试解码。 (或者你可以反复添加一个垫 角色和重试,最多3次。)
最简单的解决方案是确保您的数据包始终是4个字节的倍数。
答案 1 :(得分:0)
问题在于身份验证。 Django无法通过邮件服务器进行身份验证。一旦我解决了这个问题,问题就消失了。