공부
[Python] mail
승가비
2020. 8. 10. 21:42
728x90
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from const import MAIL_DL, MAIL_FROM, MAIL_SERVER
class Mail:
def __init__(self):
pass
@staticmethod
def send(to, cc, bcc, subject, text, html):
message = MIMEMultipart('alternative')
message['Subject'] = subject
message['From'] = MAIL_FROM # 'Your name <Your email>'
message['To'] = to
message['Cc'] = cc + ',' + MAIL_DL
message['Bcc'] = bcc
if html is not None:
body = MIMEText(html, 'html')
else:
body = MIMEText(text)
message.attach(body)
server = smtplib.SMTP(MAIL_SERVER)
server.set_debuglevel(1)
server.sendmail(MAIL_DL, to.split(','), message.as_string())
server.quit()
return {
'to': to,
'cc': cc,
'bcc': bcc,
'subject': subject,
'text': text,
'html': html,
}
https://gist.github.com/seunggabi/ae24029acd3f1198d7b72dddc3d770b2
mail.py
GitHub Gist: instantly share code, notes, and snippets.
gist.github.com
python — python에서 이메일의 보낸 사람 필드에 발신자 이름 추가
이메일 주소에서 공백은 유효한 문자가 아닙니다. 특수 문자는 외부 표현에서만 허용되며 큰 따옴표로 묶어야합니다. 또한 대부분의 SMTP 서버는 실제로 주소를 표준 형식으로 유지하기 위해 헤�
www.it-swarm.dev
728x90