동일 기능 파이썬 파일 추가
parent
b9425edee9
commit
e345684162
|
|
@ -0,0 +1,38 @@
|
|||
import smtplib
|
||||
from email import encoders
|
||||
from email.mime.base import MIMEBase
|
||||
from email.mime.multipart import MIMEMultipart
|
||||
from email.mime.text import MIMEText
|
||||
from email.encoders import encode_base64
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
SMTP_SERVER = os.getenv("SMTP_SERVER") # 네이버 smtp, 보내는 서버 기준 smtp 도메인 확인
|
||||
SMTP_USER_ID = os.getenv("SMTP_USER_ID") # 송신자 ID / 현재는 SMTP 서버 로그인 + 송신자
|
||||
SMTP_USER_PW = os.getenv("SMTP_USER_PW") # 송신자 PW / 네이버의 경우 SMTP전용 PW 발급
|
||||
SMTP_PORT = os.getenv("SMTP_PORT")# SMTP PORT, 기본 587
|
||||
|
||||
TARGET_FILE_PATH = "c:/o2o/smtp-mail-send-test/data/테스트피디엪.pdf" # 파일 경로
|
||||
file_name = "테스트 pdf.pdf" # 첨부파일명
|
||||
part = MIMEBase('application', "octet-stream")
|
||||
part.set_payload(open(TARGET_FILE_PATH,"rb").read())
|
||||
encode_base64(part)
|
||||
part.add_header('Content-Disposition', 'attachment', filename=file_name)
|
||||
|
||||
reciever = "jhyeu@o2o.kr" # 수신자
|
||||
with smtplib.SMTP(SMTP_SERVER, SMTP_PORT) as smtp:
|
||||
smtp.starttls()
|
||||
smtp.login(SMTP_USER_ID, SMTP_USER_PW)
|
||||
content = "This is an automated message being sent by Python. Python is the mastermind behind this."
|
||||
msg = MIMEMultipart()
|
||||
msg['From'] = SMTP_USER_ID
|
||||
msg['Subject'] = '메일 발송 시험'
|
||||
msg['To'] = reciever
|
||||
|
||||
body = MIMEText(content, _charset='utf-8')
|
||||
msg.attach(body)
|
||||
msg.attach(part)
|
||||
smtp.sendmail(SMTP_USER_ID, reciever, msg.as_string())
|
||||
|
||||
Loading…
Reference in New Issue