리자

장고에서 구글 SMTP 연결하여 메일 보내는 방법

How to send mail by connecting to Google SMTP in Janggo

 

https://support.google.com/accounts/answer/185833?hl=ko

 

구글에 로그인 하여 

 

보안 > 2단계 인증 선택

 

하단의 앱 비밀번호 선택

 

앱 비밀번호 생성

 

 

# 장고 myproject/settings.py

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'

EMAIL_HOST = 'smtp.gmail.com'  # Gmail SMTP 서버 주소

EMAIL_PORT = 587

EMAIL_USE_TLS = True

EMAIL_HOST_USER = '사용자아이디@gmail.com'  # 자신의 Gmail 계정

EMAIL_HOST_PASSWORD = '앱비밀번호'  # 자신의 Gmail 계정 앱 비밀번호

 

 

 

sendmail_test.py

 

from django.core.mail import send_mail

 

def send_username_email(username, email):

    subject = 'Your username'

    message = f'Your username is {username}.'

    email_from = settings.EMAIL_HOST_USER

    recipient_list = [email,]

    send_mail(subject, message, email_from, recipient_list)

 

send_username_email("보내는사람 이름", "받는사람 이메일주소")

 

 

 

|
댓글을 작성하시려면 로그인이 필요합니다.
+
제목 글쓴이 날짜 조회
19-12-19 조회 1,772
19-12-18 조회 1,737
19-12-17 조회 1,662
19-12-16 조회 1,328
19-12-15 조회 1,464
19-12-14 조회 1,368
19-12-13 조회 1,706
19-12-13 조회 1,619
19-12-12 조회 1,294
19-12-12 조회 1,083
19-12-12 조회 1,347
19-12-11 조회 1,990
19-12-11 조회 1,447
19-12-10 조회 1,147
19-12-10 조회 1,533
19-12-10 조회 1,138
19-12-09 조회 1,387
19-12-07 조회 1,599
19-12-07 조회 1,376
19-12-06 조회 1,773
19-12-06 조회 1,427
19-12-05 조회 1,372
19-12-05 조회 1,287
19-12-04 조회 2,689
19-12-04 조회 1,200
19-12-03 조회 2,755
19-12-03 조회 1,191
19-12-03 조회 1,295
19-11-19 조회 1,374
19-11-19 조회 1,571