mirror of
https://github.com/optim-enterprises-bv/Mailu.git
synced 2025-11-03 03:28:10 +00:00
Merge #2543
2543: Fix #2231: make public announcements work r=nextgens a=nextgens ## What type of PR? bug-fix ## What does this PR do? Ensure public announcements bypass filters. They can still time-out... but this is already a big improvement that we should be able to backport. ### Related issue(s) - closes #2231 ## Prerequisites Before we can consider review and merge, please make sure the following list is done and checked. If an entry in not applicable, you can check it or remove it from the list. - [ ] In case of feature or enhancement: documentation updated accordingly - [x] Unless it's docs or a minor change: add [changelog](https://mailu.io/master/contributors/workflow.html#changelog) entry file. Co-authored-by: Florent Daigniere <nextgens@freenetproject.org>
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
"""
|
||||
|
||||
import os
|
||||
import smtplib
|
||||
import json
|
||||
|
||||
from datetime import date
|
||||
@@ -420,14 +419,19 @@ class Email(object):
|
||||
|
||||
def sendmail(self, subject, body):
|
||||
""" send an email to the address """
|
||||
f_addr = f'{app.config["POSTMASTER"]}@{idna.encode(app.config["DOMAIN"]).decode("ascii")}'
|
||||
with smtplib.SMTP(app.config['HOST_AUTHSMTP'], port=10025) as smtp:
|
||||
to_address = f'{self.localpart}@{idna.encode(self.domain_name).decode("ascii")}'
|
||||
msg = text.MIMEText(body)
|
||||
msg['Subject'] = subject
|
||||
msg['From'] = f_addr
|
||||
msg['To'] = to_address
|
||||
smtp.sendmail(f_addr, [to_address], msg.as_string())
|
||||
try:
|
||||
f_addr = f'{app.config["POSTMASTER"]}@{idna.encode(app.config["DOMAIN"]).decode("ascii")}'
|
||||
ip, port = app.config['HOST_LMTP'].rsplit(':')
|
||||
with smtplib.LMTP(ip, port=port) as lmtp:
|
||||
to_address = f'{self.localpart}@{idna.encode(self.domain_name).decode("ascii")}'
|
||||
msg = text.MIMEText(body)
|
||||
msg['Subject'] = subject
|
||||
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
|
||||
def resolve_domain(cls, email):
|
||||
|
||||
@@ -21,8 +21,9 @@ def announcement():
|
||||
form = forms.AnnouncementForm()
|
||||
if form.validate_on_submit():
|
||||
for user in models.User.query.all():
|
||||
user.sendmail(form.announcement_subject.data,
|
||||
form.announcement_body.data)
|
||||
if not user.sendmail(form.announcement_subject.data,
|
||||
form.announcement_body.data):
|
||||
flask.flash('Failed to send to %s' % user.email, 'error')
|
||||
# Force-empty the form
|
||||
form.announcement_subject.data = ''
|
||||
form.announcement_body.data = ''
|
||||
|
||||
1
towncrier/newsfragments/2231.bugfix
Normal file
1
towncrier/newsfragments/2231.bugfix
Normal file
@@ -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.
|
||||
Reference in New Issue
Block a user