django 发送邮件的两个问题

基本配置

参考django doc中的文档:发送邮件

  • 配置如下,settings中配置:
EMAIL_HOST = 'smtp.163.com'
EMAIL_PORT = '25'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = '******'   # 填密码
  • 然后调用send_mail发送邮件即可
        subject = u'号码通激活'
        print name
        message = u'用户:' + name + u' 您好,首先非常感谢你的注册'\
                  + u"\n点击链接就可以激活邮箱,从而用邮箱进行登陆:" \
                  + u"http://192.168.1.163:8080/account/activate/?activation_key=" + activation_key\
                  + u"\n我们将为你提供非常好的号码相关服务:比如号码备份/群组建立/号码查找/群组活动等等,来自108网络教研室"

        print message
        send_mail(subject, message, settings.EMAIL_HOST_USER, [dst_email])

问题一:系统退信

在发送邮件的时候,遇到系统退信的情况,后来分析发现是由于中文字符太少,url太长,被邮件系统过滤掉了,加一些汉字和内容就好了; 或者考虑使用企业邮箱

问题二:发送邮件时报错

  • 报错如下:
SMTPAuthenticationError at /account/register/
(550, 'User has no permission')
Request Method: POST
Request URL:    http://192.168.1.163:8080/account/register/
Django Version: 1.7.1
Exception Type: SMTPAuthenticationError
Exception Value:    
(550, 'User has no permission')
Exception Location: /usr/lib/python2.7/smtplib.py in login, line 615
Python Executable:  /usr/bin/python
Python Version: 2.7.6
Python Path:    
['/home/zy/code/python/app/git/app/webcode',
 '/usr/local/lib/python2.7/dist-packages/gitosis-0.2-py2.7.egg',
 '/usr/lib/python2.7/dist-packages',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-i386-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/usr/lib/python2.7/lib-old',
 '/usr/lib/python2.7/lib-dynload',
 '/home/zy/.local/lib/python2.7/site-packages',
 '/usr/local/lib/python2.7/dist-packages',
 '/usr/lib/python2.7/dist-packages/PILcompat',
 '/usr/lib/python2.7/dist-packages/gst-0.10',
 '/usr/lib/python2.7/dist-packages/gtk-2.0',
 '/usr/lib/python2.7/dist-packages/ubuntu-sso-client']
Server time:    Tue, 14 Apr 2015 22:23:39 +080

解决方法:因为另外一个项目也用到了相同的方法去发送邮件,然后测试可以正常发送邮件,排除邮件服务器的问题。 然后想到了该邮箱smtp服务的开启问题。于是,登陆邮箱,开启服务就OK了。

你可能感兴趣的:(django,email)