Created
October 9, 2020 12:21
-
-
Save egeneralov/19bdfc87aa54ee09aaeb631b8a49ea3a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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