Python, 파이썬

python.gmail.로그인.메일발송

jake_kim 2020. 6. 15. 10:35
반응형

참조) https://oceancoding.blogspot.com/2019/11/smtp.html

 

선행작업)

1) 구글 계정 설정 ( Gmail 설정 아님 )

아래에서 "앱 비밀번호" 를 클릭하고 들어가, 비밀번호를 생성하면 된다.

 

 

 

2) 메일 발송 코드

import smtplib
from email.mime.text import MIMEText
 
# 세션 생성
s = smtplib.SMTP('smtp.gmail.com', 587)
 
# TLS 보안 시작
s.starttls()
 
# 로그인 인증
s.login('xxx@gmail.com', '16자리앱비밀번호')
 
# 보낼 메시지 설정
msg = MIMEText('내용 : 한글 내용')
msg['Subject'] = '제목 : 오션 코딩 학원'
 
# 메일 보내기
s.sendmail('sender@gmail.com', 'recevier@gmail.com', msg.as_string())
 
# 세션 종료
s.quit()

 

 

반응형