Skip to content

Instantly share code, notes, and snippets.

@seunggabi
Last active August 10, 2020 12:41
Show Gist options
  • Save seunggabi/ae24029acd3f1198d7b72dddc3d770b2 to your computer and use it in GitHub Desktop.
Save seunggabi/ae24029acd3f1198d7b72dddc3d770b2 to your computer and use it in GitHub Desktop.
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,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment