반응형
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import csv
import getpass
# SMTP 서버 설정
#SMTP_SERVER = 'smtp.gmail.com'
SMTP_SERVER = 'smtp.naver.com'
SMTP_PORT = 587
BOBNEWS_ID = "@"
BOBNEWS_PW = getpass.getpass("Password: ")
# 제목
title = "메일 전송 테스트"
# HTML 파일 경로
html_file_path = 'test html.txt'
# CSV 파일 경로
#csv_file_path = 'path/to/your/emails.csv'
# HTML 파일에서 내용 읽기
with open(html_file_path, 'r', encoding='utf-8') as file:
contents = file.read()
# CSV 파일에서 이메일 주소 읽기
receiver_emails = ['@']
#with open(csv_file_path, newline='', encoding='utf-8') as csvfile:
# reader = csv.reader(csvfile)
# for row in reader:
# receiver_emails.append(row[0]) # assuming the email addresses are in the first column
# SMTP 세션 생성 및 로그인
session = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
session.starttls()
session.login(BOBNEWS_ID, BOBNEWS_PW)
# 각 이메일 주소로 메일 발송
for email in receiver_emails:
# 이메일 헤더 생성
msg = MIMEMultipart()
msg['From'] = BOBNEWS_ID
msg['To'] = email
msg['Subject'] = title
msg.attach(MIMEText(contents, 'html'))
# 이메일 발송
session.sendmail(BOBNEWS_ID, email, msg.as_string())
print(f"발송 완료: {email}")
# SMTP 세션 종료
session.quit()
print("모든 이메일 발송 완료")
https://m.blog.naver.com/hankrah/221857207814
구글: G-mail 2단계 인증 풀기, 보안 수준이 낮은 앱의 엑세스 '허용'으로 바꾸기
https://forum.worksmobile.com/kr/posts/100456
네이버: 내정보(네이버ID)> 보안설정> 2단계 인증 관리하기
자동화
애용하는 서비스인데, github통해서도 가능하다
반응형
'코딩 > 파이썬' 카테고리의 다른 글
[프로그래머스] 네트워크 풀이 - Python3 (0) | 2024.04.14 |
---|---|
[Python3] AttributeError: 'list' object has no attribute 'find' 오류 해결 방법 (0) | 2024.04.12 |
[파이썬] 리스트에서 n씩 빼는 방법(같은 값 빼기 / 더하기) (0) | 2024.03.31 |
텐서플로우 set_random_seed 함수 에러, AttributeError: module 'tensorflow' has no attribute 'set_random_seed' 해결 방법 (0) | 2024.03.28 |
[Python] boto3 환경 설정, AWS CLI 설치하기 (0) | 2024.01.16 |