-
Notifications
You must be signed in to change notification settings - Fork 1
/
mail_sending.py
34 lines (28 loc) · 1.01 KB
/
mail_sending.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Moduł do obsługi wysyłania e-maili."""
from flask_mail import Mail, Message
from config import EMAIL
mail = Mail()
def common_msg(title, send_to, filename, *args):
"""Prosta funkcja do wysyłania e-maila.
title = tytuł wiadomości,
send_to = adresat,
filename = nazwa pliku w folderze static/emails,
*args - parametry dodawane do formatki
"""
msg = Message(title, recipients=[send_to])
with open('{}{}'.format(EMAIL.FILES_PATH, filename), 'r') as file:
message = file.read().format(*args)
msg.body = message
mail.send(msg)
def msg_to_all_users(subject, message, users):
"""Wiadomość wysyłana do wszystkich aktywnych użytkowników."""
with mail.connect() as conn:
for user in users:
message = message
subject = subject
msg = Message(recipients=[user.email],
body=message,
subject=subject)
conn.send(msg)