-
Notifications
You must be signed in to change notification settings - Fork 11
/
02_send_html.py
38 lines (28 loc) · 983 Bytes
/
02_send_html.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import smtplib
import os
from email.mime.text import MIMEText
def send_email():
sender = "your_email"
# your password = "your password"
password = os.getenv("EMAIL_PASSWORD")
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
try:
with open("email_template.html") as file:
template = file.read()
except IOError:
return "The template file doesn't found!"
try:
server.login(sender, password)
msg = MIMEText(template, "html")
msg["From"] = sender
msg["To"] = sender
msg["Subject"] = "С Днем Рождения! Только сегодня скидка по промокоду до 90%!"
server.sendmail(sender, sender, msg.as_string())
return "The message was sent successfully!"
except Exception as _ex:
return f"{_ex}\nCheck your login or password please!"
def main():
print(send_email())
if __name__ == "__main__":
main()