Fix #2231: make public announcements work

main
Florent Daigniere 2 years ago
parent 68bb8da2b7
commit b20bf996ec

@ -2,7 +2,6 @@
""" """
import os import os
import smtplib
import json import json
from datetime import date from datetime import date
@ -420,14 +419,19 @@ class Email(object):
def sendmail(self, subject, body): def sendmail(self, subject, body):
""" send an email to the address """ """ send an email to the address """
f_addr = f'{app.config["POSTMASTER"]}@{idna.encode(app.config["DOMAIN"]).decode("ascii")}' try:
with smtplib.SMTP(app.config['HOST_AUTHSMTP'], port=10025) as smtp: f_addr = f'{app.config["POSTMASTER"]}@{idna.encode(app.config["DOMAIN"]).decode("ascii")}'
to_address = f'{self.localpart}@{idna.encode(self.domain_name).decode("ascii")}' ip, port = app.config['HOST_LMTP'].rsplit(':')
msg = text.MIMEText(body) with smtplib.LMTP(ip, port=port) as lmtp:
msg['Subject'] = subject to_address = f'{self.localpart}@{idna.encode(self.domain_name).decode("ascii")}'
msg['From'] = f_addr msg = text.MIMEText(body)
msg['To'] = to_address msg['Subject'] = subject
smtp.sendmail(f_addr, [to_address], msg.as_string()) msg['From'] = f_addr
msg['To'] = to_address
lmtp.sendmail(f_addr, [to_address], msg.as_string())
return True
except smtplib.SMTPException:
return False
@classmethod @classmethod
def resolve_domain(cls, email): def resolve_domain(cls, email):

@ -21,8 +21,9 @@ def announcement():
form = forms.AnnouncementForm() form = forms.AnnouncementForm()
if form.validate_on_submit(): if form.validate_on_submit():
for user in models.User.query.all(): for user in models.User.query.all():
user.sendmail(form.announcement_subject.data, if not user.sendmail(form.announcement_subject.data,
form.announcement_body.data) form.announcement_body.data):
flask.flash('Failed to send to %s' % user.email, 'error')
# Force-empty the form # Force-empty the form
form.announcement_subject.data = '' form.announcement_subject.data = ''
form.announcement_body.data = '' form.announcement_body.data = ''

@ -0,0 +1 @@
Make public announcement bypass the filters. They may still time-out before being sent if there is a large number of users.
Loading…
Cancel
Save