
* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.
* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.
import openpyxl
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import schedule
import time
import pytz
from datetime import datetime
def send_email():
smtp_server = 'smtp.gmail.com'
smtp_port = 587
# Email account information
smtp_username = 'kiukjeong1472@gmail.com'
smtp_password = 'mwnweauilcbqdvat'
# Load Excel file
wb = openpyxl.load_workbook('/content/sample_data/customer_data_test.xlsx')
ws = wb['test_name_email']
# Extract recipient name and email
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):
# Email subject and body
mail_subject = "Subject"
mail_body = "Body"
# Create email message
message = MIMEMultipart()
message['From'] = smtp_username
message['To'] = email
message['Subject'] = mail_subject
# Attach body to message
message.attach(MIMEText(mail_body))
# Send email
smtp.send_message(message)
# 서울 타임존 설정
seoul_timezone = pytz.timezone('Asia/Seoul')
# Send emails on user-defined date and time
def send_emails_on_schedule(target_time):
while True:
now = datetime.now()
if now >= target_time:
send_email()
break
time.sleep(1)
# Get user input for date and time
datetime_input = input("Enter the date and time (YYYY-MM-DD HH:MM:SS): ")
target_time = datetime.strptime(datetime_input, "%Y-%m-%d %H:%M:%S")
# Schedule email sending
send_emails_on_schedule(target_time)
