Skip to content

Commit 6000a57

Browse files
authored
Add files via upload
1 parent c3eadb7 commit 6000a57

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

email_notification.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
# https://codingworld.io/project/e-mails-versenden-mit-python
5+
6+
import smtplib
7+
from email.mime.multipart import MIMEMultipart
8+
from email.mime.text import MIMEText
9+
from settings import settings
10+
11+
12+
""" Warning!
13+
14+
If you use web.de like me, you must first
15+
allow the use of smtp and imap in the settings.
16+
17+
Otherwise you will receive an error message:
18+
19+
smtplib.SMTPAuthenticationError()
20+
21+
"""
22+
23+
def email_notification(settings, subject, text):
24+
msg = MIMEMultipart()
25+
msg['From'] = settings["senderEmail"]
26+
msg['To'] = settings["empfangsEmail"]
27+
msg['Subject'] = subject
28+
29+
emailText = text
30+
msg.attach(MIMEText(emailText, 'html'))
31+
32+
server = smtplib.SMTP(settings["smtp_server"], settings["smtp_server_port"])
33+
server.starttls()
34+
server.login(settings["senderEmail"], settings["senderPasswort"])
35+
text = msg.as_string()
36+
server.sendmail(settings["senderEmail"], settings["empfangsEmail"], text)
37+
server.quit()
38+
39+
40+
if __name__ == "__main__":
41+
42+
email_notification(settings,
43+
"This is my subject",
44+
"<b>Here comes my text!</b><br><ul><li>List 1</li><li>List 2</li></ul><p>Greetings</p>")
45+

0 commit comments

Comments
 (0)