<jupyter_start><jupyter_text>send html<jupyter_code>def get_smtp():
    smtp = smtplib.SMTP('smtp.gmail.com', 587)
    smtp.ehlo()
    smtp.starttls()
    smtp.login('<EMAIL>', pickle.load( open('pw.pickle', 'rb')))
    return smtp
smtp = get_smtp()
smtp
msg = MIMEMultipart()

#제목
msg['subject'] = 'HTML 전송 테스트'

# 내용
part = MIMEText("Html 코드 보내기")
msg.attach(part)

# HTML
part_html = MIMEText('<br><a href="http://www.fastcampus.co.kr/">\
패스트캠퍼스</a>', 'html')
msg.attach(part_html)

msg  # 제목, 내용, html
# 전송
def send_mails(smtp, toAddr, msg):
    for addr in toAddr:
        msg['To'] = addr
        smtp.sendmail('<EMAIL>', addr, msg.as_string())
    smtp.quit()
smtp, toAddr, msg
send_mails(smtp, toAddr, msg)<jupyter_output><empty_output><jupyter_text>Send File<jupyter_code>smtp = get_smtp()
msg = MIMEMultipart()
msg['subject'] = 'Send file test'
part = MIMEText('파일 전송 테스트')
msg.attach(part)
# file attach - pdf
file_name = 'asdv.png'
maintype, subtype = 'application', 'octet-steam'

with open(file_name, 'rb') as fp:
    part = MIMEBase(maintype, subtype)
    part.set_payload(fp.read()) # part에 mp4 파일이 들어감
    encoders.encode_base64(part) # base64 encoding
    
part.add_header('Content-Disposition', 'attachment', filename = file_name)
msg.attach(part)
msg # 본문, 패일
send_mails(smtp, toAddr, msg)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16430171769977595, 'fraction_numerical': 0.00597460791635549, 'mean_word_length': 4.75107296137339, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '2929', 'license': 'MIT', 'n_tokens_mistral': 592, 'n_tokens_neox': 622, 'n_words': 111, 'path': '2018_06_14_Inclass_Send_Email_SMTP_Google_Email.ipynb', 'repo_name': 'jaykim-asset/datascience_review', 'size': '1369'}