You're looking at it

Homepage: https://roundabout-host.com

By using this site, you agree to have cookies stored on your device, strictly for functional purposes, such as storing your session and preferences.

Dismiss

 email_send.py

View raw Download
text/plain • 1.7 kiB
Python script, ASCII text executable
        
            
1
"""
2
This module provides auxiliary functions for sending e-mails.
3
4
Roundabout - git hosting for everyone <https://roundabout-host.com>
5
Copyright (C) 2023-2025 Roundabout developers <root@roundabout-host.com>
6
7
This program is free software: you can redistribute it and/or modify
8
it under the terms of the GNU Affero General Public License as published by
9
the Free Software Foundation, either version 3 of the License, or
10
(at your option) any later version.
11
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU Affero General Public License for more details.
16
17
You should have received a copy of the GNU Affero General Public License
18
along with this program. If not, see <http://www.gnu.org/licenses/>.
19
"""
20
21
import config
22
from jinja2 import Environment, FileSystemLoader, select_autoescape
23
import smtplib
24
from email.mime.multipart import MIMEMultipart
25
from email.mime.text import MIMEText
26
27
28
def make_multipart_message(subject, sender, receiver, template, **kwargs):
29
env_html = Environment(
30
loader=FileSystemLoader("email_templates"),
31
autoescape=select_autoescape(["html", "xml"])
32
)
33
env_plain = Environment(loader=FileSystemLoader("email_templates"))
34
35
message = MIMEMultipart("alternative")
36
message["Subject"] = subject
37
message["From"] = sender
38
message["To"] = receiver
39
40
text = MIMEText(env_html.get_template(template+".txt").render(**kwargs, config=config), "plain")
41
html = MIMEText(env_html.get_template(template+".html").render(**kwargs, config=config), "html")
42
43
message.attach(text)
44
message.attach(html)
45
46
return message.as_string()
47