# Html 형식의 본문 내용 (cid로 이미 첨부 파일을 링크했다.)
html = """
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>하루 이슈</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body style="margin: 0; padding: 0;">
<table align="center" border="0" cellpadding="0" cellspacing="0" width="600" style="border: 1px solid #cccccc;">
<tr>
<td align="center" bgcolor="#bdd7ee" style="padding: 40px 0 30px 0;">
<img src="cid:hi" alt="Creating Email Magic" width="600" height="380" style="display: block;" />
</td>
</tr>
<tr>
<td bgcolor="#ffffff" style="padding: 40px 30px 40px 30px;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td font-family: 'Noto Sans KR', sans-serif;>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="260" valign="top" font-family:Noto Sans KR, sans-serif; font-size: 16px; line-height: 20px;">
<h2>커뮤니티 인기 키워드 100</h2>
<img src="cid:wc1" alt="Creating Email Magic" width="250" height="250" style="display: block;" />
</td>
<td style="font-size: 0; line-height: 0;" width="20">
</td>
<td width="260" valign="top" font-family:Noto Sans KR, sans-serif; font-size: 16px; line-height: 20px;">
<h2>사설 주요 키워드 100</h2>
<img src="cid:wc2" alt="Creating Email Magic" width="250" height="250" style="display: block;" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td style="padding: 20px 0 30px 0; font-family:Noto Sans KR, sans-serif; font-size: 16px; line-height: 20px;">
<p>오늘 하루도 수고하셨습니다. 하이와 함께 행복한 하루를 마무리하세요!</p>
<br>
<br>
</td>
</tr>
<tr>
<td>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="260" valign="top">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td bgcolor="#3B89A3" align="center" style="padding: 20px 30px 20px 30px;">
<img src="cid:issue" alt="" width="50%" height="100" style="display: block;" />
</td>
</tr>
<tr>
<td style="padding: 10px 0 30px 0; font-family:Noto Sans KR, sans-serif; font-size: 16px; line-height: 20px;">
<h3 style="font-family:Noto Sans KR, sans-serif;">오늘의 커뮤니티 인기 키워드</h3>
<details><p style="line-height:180%">{1}</p>
<summary>{0}
</summary>
</details>
<br>
<details><p style="line-height:180%">{3}</p>
<summary>{2}
</summary>
</details>
<br>
<details><p style="line-height:180%">{5}</p>
<summary>{4}
</summary>
</details>
<br>
<details><p style="line-height:180%">{7}</p>
<summary>{6}
</summary>
</details>
<br>
<details><p style="line-height:180%">{9}</p>
<summary>{8}
</summary>
</details>
</td>
</tr>
</table>
</td>
<td style="font-size: 0; line-height: 0;" width="20">
</td>
<td width="260" valign="top">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td bgcolor="#3B89A3" align="center" style="padding: 20px 30px 20px 30px;">
<img src="cid:news" alt="" width="50%" height="100" style="display: block;" />
</td>
</tr>
<tr>
<td style="padding: 10px 0 30px 0; font-family:Noto Sans KR, sans-serif; font-size: 16px; line-height: 20px;">
<h3 style="font-family:Noto Sans KR, sans-serif;">오늘의 사설 주요 키워드</h3>
<details><p style="line-height:180%">{11}</p>
<summary>{10}
</summary>
</details>
<br>
<details><p style="line-height:180%">{13}</p>
<summary>{12}
</summary>
</details>
<br>
<details><p style="line-height:180%">{15}</p>
<summary>{14}
</summary>
</details>
<br>
<details><p style="line-height:180%">{16}</p>
<summary>오늘 자주 등장한 키워드
</summary>
</details>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td bgcolor="#bdd7ee" style="padding: 30px 30px 30px 30px;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="75%"; style="color: #000000; font-family: Arial, sans-serif; font-size: 14px;">
® 하루이슈, Hi 2021<br/>
<a href="" style="color: #000000;"><font color="#000000">Unsubscribe</font></a> to this newsletter instantly
</td>
<td align="right">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<a href="http://www.twitter.com/">
<img src="cid:tw" alt="Twitter" width="38" height="38" style="display: block;" border="0" />
</a>
</td>
<td style="font-size: 0; line-height: 0;" width="20"> </td>
<td>
<a href="http://www.facebook.com/">
<img src="cid:fb" alt="Facebook" width="38" height="38" style="display: block;" border="0" />
</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
""".format(keyword_top5[0], articlestr1, keyword_top5[1], articlestr2, keyword_top5[2], articlestr3, keyword_top5[3], articlestr4, keyword_top5[4], articlestr5, sendingKeywords[0], content1, sendingKeywords[1], content2, sendingKeywords[2], content3, dfCSV["text"].tolist())
msg = MIMEText(html, 'html')
# 메시지를 확인한다.
# Data 영역의 메시지에 바운더리 추가
data.attach(msg);
print(data);
# 메일 서버와 telnet 통신 개시
server = smtplib.SMTP_SSL('smtp.naver.com',465);
#server = smtplib.SMTP('smtp.gmail.com',587);
# 메일 통신시 디버그
server.set_debuglevel(1);
# 헤로 한번 해주자.(의미 없음)
server.ehlo();
# tls 설정 주문 - tls 587 포트의 경우
#server.starttls();
# 헤로 또 해주자.(의미 없음)
server.ehlo();
# 로그인 한다.
server.login("ID", "P/W!"); # 아이디, 패스워드 입력
# 심심하니 또 헤로 해주자.(의미 없음)
server.ehlo();
# MAIL(송신자) 설정
sender = data['From'];
# RCPT(수신자), 리스트로 보낸다.
# 수신자 추가
receiver = data['To'].split(",");
# # 참조자 추가
# if data['Cc'] is not None:
# receiver += data['Cc'].split(",");
# # 숨은 참조자 추가
# if data['Bcc'] is not None:
# receiver += data['Bcc'].split(",");
# 메일 프로토콜 상 MAIL, RCPT, DATA 순으로 메시지를 보내야 하는데 이걸 sendmail함수에서 자동으로 해준다.
server.sendmail(sender, receiver, data.as_string());
# QUIT을 보내고 접속을 종료하고 메일을 보낸다.
server.quit();