Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save egeneralov/19bdfc87aa54ee09aaeb631b8a49ea3a to your computer and use it in GitHub Desktop.
Save egeneralov/19bdfc87aa54ee09aaeb631b8a49ea3a to your computer and use it in GitHub Desktop.
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
import email.utils
message = MIMEMultipart('alternative')
message['From'] = 'Sender Name <${USER}@${DOMAIN}>'
message['To'] = 'Receiver Name <${TO}>'
message['Subject'] = 'Any subject'
message['Message-Id'] = email.utils.make_msgid()
message['Date'] = email.utils.formatdate(timeval=None, localtime=False, usegmt=False)
message.attach(MIMEText('# A Heading\nSomething else in the body', 'plain'))
message.attach(MIMEText('<h1 style="color: blue">A Heading</a><p>Something else in the body</p>', 'html'))
server = smtplib.SMTP('mail.${DOMAIN}:587')
server.starttls()
print(
server.login('${USER}@${DOMAIN}', '${PASSWORD}')
)
print(
server.sendmail(
'${USER}@${DOMAIN}',
"${TO}>",
message.as_string()
)
)
server.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment