diff --git a/core/admin/mailu/models.py b/core/admin/mailu/models.py index e42978cd..65ba1ef8 100644 --- a/core/admin/mailu/models.py +++ b/core/admin/mailu/models.py @@ -3,11 +3,14 @@ from mailu import app, db, dkim, login_manager from sqlalchemy.ext import declarative from passlib import context, hash from datetime import datetime +from email.mime import text + import re import time import os import glob +import smtplib # Many-to-many association table for domain managers @@ -153,6 +156,18 @@ class Email(object): primary_key=True, nullable=False, default=updater) + def sendmail(self, subject, body): + """ Send an email to the address. + """ + from_address = '{}@{}'.format( + app.config['POSTMASTER'], app.config['DOMAIN']) + with smtplib.SMTP('smtp', port=10025) as smtp: + msg = text.MIMEText(body) + msg['Subject'] = subject + msg['From'] = from_address + msg['To'] = self.email + smtp.sendmail(from_address, [self.email], msg.as_string()) + def __str__(self): return self.email @@ -230,6 +245,11 @@ class User(Base, Email): emails.extend(domain.aliases) return emails + def send_welcome(self): + if app.config["WELCOME"].lower() == "true": + self.sendmail(app.config["WELCOME_SUBJECT"], + app.config["WELCOME_BODY"]) + @classmethod def login(cls, email, password): user = cls.query.get(email) diff --git a/core/admin/mailu/ui/templates/announcement.html b/core/admin/mailu/ui/templates/announcement.html index ced68297..7dd34d3f 100644 --- a/core/admin/mailu/ui/templates/announcement.html +++ b/core/admin/mailu/ui/templates/announcement.html @@ -4,10 +4,6 @@ {% trans %}Public announcement{% endtrans %} {% endblock %} -{% block subtitle %} -{% trans %}from{% endtrans %} {{ from_address }} -{% endblock %} - {% block content %} {% call macros.box() %}