커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
메일 발송 시간이 지나도 계속 하여 실행되고 메일 발송이 안되는데 뭐가 잘못되었나요?
[왕초보] ChatGPT 300% 활용하기 v0
4주차
북마크
정*욱
댓글
3
추천
0
조회수
7
조회수
7
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.





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)







취소
 공유
취소
댓글 0
댓글 알림
나의얼굴