1、官方文档的django的一个小demo:
ss = send_mail( 'Subject here', 'Here is the message.', '[email protected]', ['[email protected]'], fail_silently=False, )
2、在settings中配置环境:
EMAIL_USE_SSL = True EMAIL_HOST = 'smtp.163.com' # 如果是 qq 改成 smtp.qq.com EMAIL_PORT = 465 #端口 EMAIL_HOST_USER = '[email protected]' # 帐号 EMAIL_HOST_PASSWORD = '~~~password' # 密码 DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
3、完整代码:
def secd_emdil(request):
s_true = send_mail(
'Subject here',
'Here is the message.',
'[email protected]',
['[email protected]'],
fail_silently=False,
)
if s_true:
return JsonResponse({'code':200,'data':None})
else:
return JsonResponse({'code':500,'data':None})
4、配置路由:
path('send/', views.secd_emdil),
5、发送成功,在垃圾邮件中