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