django 发送邮件
django 发送126邮箱
-
首先取得网易授权
1. 设置 2.左侧客户端授权码 3.自定义授权码 也就是你配置文件中的密码
-
配置文件
# 邮件 EMAIL_HOST = 'smtp.126.com' # 设置端口号,为数字 EMAIL_PORT = 25 #设置发件人邮箱 EMAIL_HOST_USER = 'fuchongjun@126.com' # 设置发件人 授权码 EMAIL_HOST_PASSWORD = 'ice115816' # 设置是否启用安全链接 EMAIL_USER_TLS = True EMAIL_USER_TLS = False DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
-
views.py
from django.core.mail import send_email from django.conf import settings def sendMsg(): res = send_mail('关于中秋节放假通知', '中秋节放三天假', settings.DEFAULT_FROM_EMAIL, ['imock@sina.com']) if res == 1: return HttpResponse('邮件发送成功') else: return HttpResponse('邮件发送失败')
-
一些常用的邮箱配置
-
126邮箱
# 邮件设置 EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.126.com' EMAIL_PORT = 25 # 发送邮件的邮箱 EMAIL_HOST_USER = 'fuchongjun@126.com' # 在邮箱中设置的客户端授权密码 EMAIL_HOST_PASSWORD = 'admin123' # 收件人看到的发件人 EMAIL_FROM = EMAIL_HOST_USER # 设置是否启用安全链接 EMAIL_USER_TLS = True EMAIL_USER_TLS = False
-
163邮箱
#邮件发送配置 EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.163.com' EMAIL_PORT = 25 #发送邮件的邮箱 EMAIL_HOST_USER = '*******@163.com' #在邮箱中设置的客户端授权密码 EMAIL_HOST_PASSWORD = '******' #收件人看到的发件人 EMAIL_FROM = 'python<*****@163.com>' # 需要和邮箱号码一致
-
新浪邮箱
#邮件发送配置 EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = "smtp.sina.com" EMAIL_PORT = 25 EMAIL_HOST_USER = "xxx@sina.com" # 你的邮箱账号 EMAIL_HOST_PASSWORD = "xxxx" # 你的邮箱密码 EMAIL_USE_TLS = False # 这里是 False EMAIL_FROM = "xxx@sina.com" # 你的邮箱账号
-
QQ邮箱
#邮件发送配置 EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.qq.com' EMAIL_PORT = 25 EMAIL_HOST_USER = 'xxx@qq.com' # 你的 QQ 账号 EMAIL_HOST_PASSWORD = '授权码' EMAIL_USE_TLS = True # 这里必须是 True,否则发送不成功 EMAIL_FROM = 'EMAIL_HOST_USER # 你的 QQ 账号
-
Gmail邮箱
#邮件发送配置 EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' EMAIL_HOST = 'smtp.gmail.com' EMAIL_PORT = 587 EMAIL_HOST_USER = 'xxx' EMAIL_HOST_PASSWORD = 'xxx' # 下面两项只能有一个为True EMAIL_USE_TLS = True EMAIL_USE_SSL = False
-