1、本实例采用163邮箱发送邮件
settings.py 增加如下配置项:
#send email
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' #email后端
EMAIL_USE_TLS = False #是否使用TLS安全传输协议
EMAIL_HOST = 'smtp.163.com'
EMAIL_PORT = 25 #发件箱的SMTP服务器端口
EMAIL_HOST_USER = 'from@163.com' #发送邮件的邮箱地址
EMAIL_HOST_PASSWORD = '123456' #发送邮件的邮箱密码
163免费邮客户端设置的POP3、SMTP、IMAP地址:http://help.163.com/09/1223/14/5R7P3QI100753VB8.html
2、发送邮件
格式: send_mail('邮件名','内容','发件地址',['收件地址(可多个收件人)'],)
[root@测试服 webproject]# python manage.py shell
Python 2.7.9 (default, May 19 2017, 16:38:41)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.core.mail import send_mail
>>> send_mail('Subject here', 'Here is the message.','1365079xxxx@163.com',['82419xxxx@qq.com'],fail_silently=False)
1
>>>