
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
4주차 숙제 - 비밀번호를 새로 만들어서 넣어 줬더니 에러는 없는데 계속 뺑뺑 돌아요.
작성한 코드 및 에러 메세지
import openpyxl
import smtplib
!pip install schedule
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import schedule
import time
import datetime
import pytz
# apt-get 명령어는 리눅스 환경에서 사용되는 명령어이므로 생략
# !apt-get install python3-pip
# !pip3 install pytz
def send_email():
smtp_server = 'smtp.gmail.com'
smtp_port = 587
# 앱 비밀번호 관련 정보 입력
smtp_username = 'cosby2000@gmail.com'
smtp_password = 'dqcc **** **** ****'
# 엑셀 파일 이름 입력
wb = openpyxl.load_workbook('source.xlsm')
# 시트 이름 입력
ws = wb['마케팅데이터터'] # '마케팅데이터터'를 '마케팅데이터'로 수정
# 이메일 보낼 사람과 이메일 정보 가져오기
name_list = []
email_list = []
for row in ws.iter_rows(min_row=2, values_only=True):
name = row[0]
email = row[1]
name_list.append(name)
email_list.append(email)
with smtplib.SMTP(smtp_server, smtp_port) as smtp:
smtp.starttls()
smtp.login(smtp_username, smtp_password)
for name, email in zip(name_list, email_list):
# 메일 제목, 본문 내용 작성
mail_subject = "수고 많습니다."
mail_body = "건투를 빕니다.\n"
# 메일 생성
message = MIMEMultipart()
message['From'] = smtp_username
message['To'] = email
message['Subject'] = mail_subject
# 메일 본문 추가
message.attach(MIMEText(mail_body))
# 메일 전송
smtp.send_message(message)
# 매주 월요일과 수요일 오전 10시에 메일 발송하기
def monday_wednesday_email():
now = datetime.datetime.now(pytz.timezone('Asia/Seoul'))
# 매주 월요일과 수요일 10:00에 메일 보내기
if now.strftime("%A") in ["Monday", "Wednesday"] and now.strftime("%H:%M") == "10:00":
send_email()
# schedule.every().minute.do(friday_email) # 매분마다 실행하는 부분 주석 처리
schedule.every().monday.at("10:00").do(monday_wednesday_email)
schedule.every().wednesday.at("10:00").do(monday_wednesday_email)
while True:
schedule.run_pending()
time.sleep(1)오류 발생 시, 작성한 코드 전체와 에러 메시지를 첨부해 주세요.
Tip 1) </> 아이콘을 눌러 코드박스를 만들어 보세요.
Tip 2) Ctrl+A(맥의 경우 Command+A) 단축키로 코드를 한 번에 선택할 수 있어요!
