# HG changeset patch # User Dennis Fink # Date 2015-03-07 18:40:19 # Node ID 3b6c157e828eb7e97385da30a0962430efda4c0f # Parent 4bc2ff06c4c69a783989e57052ff75745c9ec02c Send membership messages to multiple addresses diff --git a/ennstatus/root/functions.py b/ennstatus/root/functions.py --- a/ennstatus/root/functions.py +++ b/ennstatus/root/functions.py @@ -7,11 +7,6 @@ from ennstatus.status.functions import m def send_membership_mail(form): try: - msg = Message('New membership application', sender='ennstatus@enn.lu') - - recipient = current_app.config['ENNSTATUS_MEMBERSHIP_MAIL'] - msg.add_recipient(recipient) - body = render_template('root/membership_mail.txt', username=form.username.data, email=form.email.data, @@ -25,16 +20,21 @@ def send_membership_mail(form): country=form.country.data, gpg=form.gpg.data ) - current_app.logger.debug('Before encryption') - current_app.logger.debug(body) - if current_app.extensions['gnupg']: - body = str(current_app.extensions['gnupg'].encrypt(body, recipient, - always_trust=True)) - current_app.logger.debug('After encryption') - current_app.logger.debug(body) - msg.body = body - mail.send(msg) + recipients = current_app.config['ENNSTATUS_MEMBERSHIP_MAIL'] + with mail.connect() as conn: + for recipient in recipients: + msg = Message('New membership application', sender='ennstatus@enn.lu') + msg.add_recipient(recipient) + current_app.logger.debug('Before encryption') + current_app.logger.debug(body) + if current_app.extensions['gnupg']: + body = str(current_app.extensions['gnupg'].encrypt(body, recipient, + always_trust=True)) + current_app.logger.debug('After encryption') + current_app.logger.debug(body) + msg.body = body + conn.send(msg) flash('Application successfully sended!', 'success') except KeyError: flash('Internal server error! Please get in touch with us at info@enn.lu!', 'error')