-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmailsender.py
More file actions
28 lines (23 loc) · 825 Bytes
/
Copy pathmailsender.py
File metadata and controls
28 lines (23 loc) · 825 Bytes
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
from datetime import date
from email.message import Message
from smtplib import SMTP
class MailSender:
def __init__(self, host, usr, pwd, sender):
self.host = host
self.usr = usr
self.pwd = pwd
self.sender = sender
def __enter__(self):
self.smtp = SMTP(host=self.host)
self.smtp.starttls()
self.smtp.login(self.usr, self.pwd)
def sendmail(self, email, body):
msg = Message()
msg["subject"] = "foodsharing.de unbelegte Abholungen (Stand: {})".format(
date.today().strftime("%d.%m.%Y"))
msg["from"] = self.sender
msg["to"] = email
msg.set_payload(body, charset="utf-8")
self.smtp.send_message(msg, self.sender, email)
def __exit__(self, exc_type, exc_val, exc_tb):
self.smtp.quit()