Python2.7 + Django1.10.0python
setting.py中添加以下代碼shell
# Host for sending email. EMAIL_HOST = 'smtp.qq.com' # Port for sending email. EMAIL_PORT = 587 # Optional SMTP authentication information for EMAIL_HOST. EMAIL_HOST_USER = 'gjp_1988@qq.com' EMAIL_HOST_PASSWORD = '獲取的受權碼' EMAIL_USE_TLS = True #必須爲True EMAIL_USE_SSL = False EMAIL_SSL_CERTFILE = None EMAIL_SSL_KEYFILE = None EMAIL_TIMEOUT = None # Default email address to use for various automated correspondence from # the site managers. DEFAULT_FROM_EMAIL = 'gjp_1988@qq.com'
進入shell界面django
hester@hester-virtual-machine:~/django_project/sample1/mysite$ ./manage.py shell
fPython 2.7.12 (default, Nov 12 2018, 14:36:49)
Type "copyright", "credits" or "license" for more information.
IPython 2.4.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: from django.core.mail import send_mail In [2]: email_title = 'from hester' In [3]: email_body = 'password reset' In [4]: email = 'gjp_1988@163.com' In [5]: send_mail(email_title,email_body,'gjp_1988@qq.com',[email])
若是返回值爲1表示發送成功,登陸163郵箱查看收件箱安全