리자

장고에서 구글 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("보내는사람 이름", "받는사람 이메일주소")

 

 

 

|
댓글을 작성하시려면 로그인이 필요합니다.
+
제목 글쓴이 날짜 조회
24-02-08 조회 1,035
24-01-19 조회 854
23-12-24 조회 846
23-08-03 조회 877
23-07-27 조회 1,098
23-07-27 조회 966
23-07-18 조회 1,374
23-07-12 조회 1,083
23-07-12 조회 1,085
23-07-07 조회 1,387
23-06-30 조회 1,320
23-06-28 조회 1,143
22-09-04 조회 1,446
22-08-17 조회 1,491
22-07-22 조회 1,506
22-05-24 조회 1,523
22-02-02 조회 1,456
21-12-29 조회 1,733
21-12-24 조회 1,653
21-12-15 조회 1,889
21-05-29 조회 1,654
21-05-01 조회 2,941
21-03-16 조회 1,646
21-03-16 조회 1,461
21-03-01 조회 1,577
21-02-16 조회 2,050
21-01-02 조회 2,046
20-12-14 조회 1,759
20-12-02 조회 1,953
20-12-02 조회 1,963