파이썬 메일보내기 설명 및 코딩
https://www.youtube.com/watch?v=eTEwc_Amx9Q
email_aicoin_02.py--------------------
import security
import smtplib
from email.mime.text import MIMEText
import pyautogui as pg
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication
# 함수 시작
def fn_send(msg_to_list_i):
email_from = 'i@gmail.com'
# email_to = 'i@naver.com'
email_to = msg_to_list_i
email_pw = security.gmail_pw
email_smtp_server_name = 'smtp.gmail.com'
email_smtp_port = 587 # SMTP 포트 (TLS) : 587 SMTP 포트 (SSL) : 465
contents_text = '「본문」3 파이썬 메일보내기 설명 및 코딩 - 첨부파일'
# 여러 MIME 넣기
msg = MIMEMultipart()
# msg = MIMEText(contents_text)
contents_multipart = MIMEText(contents_text)
msg.attach(contents_multipart)
msg['Subject'] = '「제목」3 ai코드 email 강의 - 첨부파일'
msg['From'] = email_from
msg['To'] = email_to
# 첨부 파일 추가
# etc_file_name01 = 'test.txt'
# etc_file_name02 = 'tcl.xls'
# etc_file_name = 'f15ex1000.jpg'
files = ['test.txt','tcl.xls','f15ex1000.jpg']
for etc_file_name in files:
with open(etc_file_name,'rb') as etc_file:
etc_multipart = MIMEApplication(etc_file.read()) # 바이너리 형태로 파일 읽고
etc_multipart.add_header('Content-Disposition', 'attachment', filename=etc_file_name)
msg.attach(etc_multipart)
# server = smtplib.SMTP_SSL('smtp.kakao.com')
server = smtplib.SMTP(email_smtp_server_name, email_smtp_port) # 메일서버 연결
server.starttls() # TLS 보안 처리
server.login(email_from,email_pw) # 로그인
server.sendmail(email_from, email_to, msg.as_string()) # 메일전송, 문자열로 변환
server.quit() # SMTP 서버 연결 종료
# def fn_send_print(msg_to_list_i):
# print(msg_to_list_i)
msg_to_list = ['i@daum.net', 'i@naver.com', 'i@yahoo.co.jp']
for i in msg_to_list:
fn_send(i)
print(i,"OK")
a = pg.alert(text='이메일 전송완료', title='이메일 보내기', button='OK')
====================
'컴퓨터 > Python' 카테고리의 다른 글
excel pandas pyqt5 qtablewidget email 급여명세서 (0) | 2022.09.05 |
---|---|
excel to pdf (0) | 2022.08.28 |
코딩나우-pandas (0) | 2022.08.27 |
프로그래머 김플 스튜디오 (0) | 2022.08.26 |
업무의 잔머리 (0) | 2022.08.26 |