setting.py
1 # mail configuration 2 EMAIL_BACKEND = ' django.core.mail.backends.smtp.EmailBackend ' . 3 EMAIL_HOST = ' smtp.exmail.qq.com ' # E-mail server address . 4 EMAIL_HOST_USER = ' [email protected] ' # not including '@ 126.com' suffix 5 EMAIL_HOST_PASSWORD = '' # non-mail password 6 EMAIL_PORT = 25 7 EMAIL_USE_TLS = True 8 EMAIL_FROM = ' [email protected] ' # Set the default sender is not set, the problem does not occur in this case, but the actual work in practice django, the problem occurs, see http://blog.chinaunix.net/uid-21142030-id-5768057 .html
view.py
. 1 from the django.core.mail Import the send_mail 2 from dj_01 Import Settings . 3 . 4 DEF Send (Request): . 5 MSG = ' server running well ' . 6 the send_mail ( . 7 Subject = ' Note that this is a test message Django ' , . 8 Message = MSG , . 9 FROM_EMAIL = settings.EMAIL_HOST_USER, 10 RECIPIENT_LIST = [ " [email protected] " , " [email protected] "], # Here pay attention to replace their own purposes mailbox, or to send to my email came :) 11 fail_silently = False, 12 ) 13 return HttpResponse ( ' test message has been sent. Please check ' )