Django-DRF-메일박스로 등록 메일 보내기

메일박스로 보내는 웹 페이지
<div style="height: 400px;background-color: whitesmoke;margin: 0 auto;">
     <h2 style="text-align: center;padding-top: 15px;">XX </h2>
     <div style="margin: 0 auto;background-color: white;height: 200px;width: 500px;border: 1px solid rgb(172, 172, 172);">
          <h3 style="border-bottom: 1px solid  rgb(172, 172, 172);height: 40px;line-height: 40px;margin-top: 0;padding-left: 25px;">    </h3>
          <p style="margin-left: 25px;color:steelblue;">  ! yanggeol@qq.com</p>
          <p style="margin-left: 25px;color:steelblue;">    XX</p>
          <p style="margin-left: 25px;color:steelblue;">965341</p>
          <p style="margin-left: 25px;color:gray;">@ginet.com</p>
      </div>
</div>

코드
setting.py 구성 163
#       
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.163.com'
EMAIL_PORT = 25
EMAIL_USE_SSL = True
#EMAIL_USE_TLS = True #    , EMAIL_USE_SSL    ,      True
#        
EMAIL_HOST_USER = '[email protected]'
#               
EMAIL_HOST_PASSWORD = 'xxxxx'
#          
EMAIL_FROM = 'XX'  #          

qq 메일박스 설정
#   qq       
EMAIL_HOST = 'smtp.qq.com'
  
EMAIL_HOST_USER = '[email protected]'
   
EMAIL_HOST_PASSWORD = 'xxxx'
  
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_FROM = '[email protected]'           

뷰에 추가
from rest_framework.views import APIView
from rest_framework.response import Response
from django.core.mail import send_mail
from django.conf import settings

class EmailView(APIView):
    def post(self, request, *args, **kwargs):
       from_who = settings.EMAIL_FROM  #            
       to_who = '******@163.com'  #     
       subject = '     '  #      
       #      
       message = '    '  #             message
       meg_html = '                    '  #     html
       send_mail(subject, message, from_who, [to_who], html_message=meg_html)
    return HttpResponse("ok")

좋은 웹페이지 즐겨찾기