-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgmail.py
More file actions
76 lines (30 loc) · 1019 Bytes
/
gmail.py
File metadata and controls
76 lines (30 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: cp949 -*-
import mimetypes
import mysmtplib
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
#global value
host = "smtp.gmail.com" # Gmail STMP 서버 주소.
port = "587"
htmlFileName = "logo.html"
senderAddr = "prof.youngsik.kim@gmail.com" # 보내는 사람 email 주소.
recipientAddr = "arm7tdmi@naver.com" # 받는 사람 email 주소.
msg = MIMEBase("multipart", "alternative")
msg['Subject'] = "Test email in Python 3.5"
msg['From'] = senderAddr
msg['To'] = recipientAddr
# MIME 문서를 생성합니다.
htmlFD = open(htmlFileName, 'rb')
HtmlPart = MIMEText(htmlFD.read(),'html', _charset = 'UTF-8' )
htmlFD.close()
# 만들었던 mime을 MIMEBase에 첨부 시킨다.
msg.attach(HtmlPart)
# 메일을 발송한다.
s = mysmtplib.MySMTP(host,port)
#s.set_debuglevel(1) # 디버깅이 필요할 경우 주석을 푼다.
s.ehlo()
s.starttls()
s.ehlo()
s.login("prof.youngsik.kim@gmail.com","Mina2136")
s.sendmail(senderAddr , [recipientAddr], msg.as_string())
s.close()