最近用Django写某网站,当配置163邮箱设置完成后,出现535错误即:smtplib.SMTPAuthenticationError: (535, b'Error: authentication failed')
Django初始配置邮箱设置
EMAIL_HOST = "smtp.163.com" # 邮箱服务器EMAIL_PORT = 25EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST_USER = "xxxxx" # 邮箱用户名EMAIL_HOST_PASSWORD = "xxxxx" # 邮箱账号密码,EMAIL_USE_TLS = FalseEMAIL_FROM = "xxxxx" # 163邮箱用户名,同EMAIL_HOST_USER
出现原因
163邮箱配置中EMAIL_HOST_PASSWORD不能填写自己的163账号密码,而是应该填写授权码。如果填写163账号密码则会报535错误即smtplib.SMTPAuthenticationError: (535, b'Error: authentication failed')。授权码在163邮箱的设置中获得,如下图所示:
解决方法535错误方法
Django配置改为
EMAIL_HOST = "smtp.163.com" # 邮箱服务器EMAIL_PORT = 25EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' #EMAIL_HOST_USER = "xxxxx" # 163邮箱用户名EMAIL_HOST_PASSWORD = "xxxxx" # 填写授权码EMAIL_USE_TLS = FalseEMAIL_FROM = "xxxxx" # 163邮箱用户名,同EMAIL_HOST_USER