리자

장고에서 구글 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-11-19 조회 1,259
19-11-08 조회 1,304
19-11-07 조회 1,304
19-11-07 조회 1,439
19-10-30 조회 1,157
19-10-25 조회 1,067
19-10-24 조회 1,128
19-10-24 조회 1,384
19-09-20 조회 5,619
19-08-07 조회 1,498
19-06-11 조회 1,120
19-06-09 조회 2,309
19-06-05 조회 2,000
19-06-04 조회 1,386
19-06-04 조회 1,758
19-06-03 조회 1,507
19-06-03 조회 1,291
19-06-03 조회 1,264
19-06-03 조회 3,723
19-06-02 조회 1,678
19-06-01 조회 1,959
19-06-01 조회 1,733
19-06-01 조회 1,738
19-06-01 조회 1,886
19-06-01 조회 1,968
19-05-31 조회 1,936
19-05-31 조회 2,386
19-05-31 조회 2,036
19-05-31 조회 1,652
19-05-31 조회 2,097