커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
서울 타임존 설정했고 에러도 안나는데 메일일 다른시간으로 메일을 보낼예정이라고 나오는데 해결방법요?
[왕초보] ChatGPT 300% 활용하기 v0
4주차
북마크
정*욱
댓글
5
추천
0
조회수
17
조회수
17
답변 완료

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

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


5초후 발송했는데 ....시간이



#input을 이용한 delaytime 설정

import openpyxl

import smtplib

from email.mime.text import MIMEText

from email.mime.multipart import MIMEMultipart

import time

from datetime import datetime, timedelta


def send_email():

    smtp_server = 'smtp.gmail.com'

    smtp_port = 587

    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 = "2주차 숙제"

            mail_body = "이메일 발송 예정 시간: {}".format(target_time.strftime("%Y-%m-%d %H:%M:%S"))

            # 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')


# Get user input for delay time

delay_str = input("Enter the delay time for sending email (in seconds): ")

delay_seconds = int(delay_str)


# Calculate the target time

target_time = datetime.now() + timedelta(seconds=delay_seconds)


# Wait until the target time and then send email

while datetime.now() < target_time:

    remaining_time = (target_time - datetime.now()).total_seconds()

    print("Waiting for {:.1f} seconds until sending email...".format(remaining_time))

    time.sleep(1)


send_email()보고 계신 화면 전체를 캡처해 주시면, 튜터님들이 빠르게 상황을 이해할 수 있어요.




작성한 코드 및 에러 메세지

스파르타 즉문즉답


Tip 1) </> 아이콘을 눌러 코드박스를 만들어 보세요.

Tip 2) Ctrl+A(맥의 경우 Command+A) 단축키로 코드를 한 번에 선택할 수 있어요!




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