Skip to content

Instantly share code, notes, and snippets.

@chingjunetao
Created July 31, 2021 14:56
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
def schedule_email(event, context):
msg = MIMEMultipart()
fromaddr = 'sender@hotmail.com'
msg['From'] = fromaddr
msg["To"] = "receiver@gmail.com"
msg['Subject'] = "Test Report"
htmlEmail = """
<p> Dear June, <br/><br/>
Please find the attached monthly Report below.<br/><br/>
<br/></p>
Thank you! <br/><br/>
Best Regards, <br/>
June </p>
<br/><br/>
<font color="red">Please do not reply to this email as it is auto-generated via GCP. </font>
"""
msg.attach(MIMEText(htmlEmail, 'html'))
server = smtplib.SMTP('smtp.office365.com', 587)
server.starttls()
server.login(fromaddr, "password")
text = msg.as_string()
server.sendmail(fromaddr, ['receiver@gmail.com'], text)
server.quit()
print("Email are sent successfully!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment