Skip to content
Snippets Groups Projects
Verified Commit 5300cd91 authored by nd's avatar nd
Browse files

do not fail if mail could not be sent, closes #9

parent 87882cc2
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<label for="user-password1">New Password</label> <label for="user-password1">New Password</label>
<input type="password" class="form-control" id="user-password1" name="password1" required="required" tabindex = "2"> <input type="password" class="form-control" id="user-password1" name="password1" required="required" tabindex = "2">
<small class="form-text text-muted"> <small class="form-text text-muted">
At least 8 characters, no other special requirements. But please don't be stupid and use a password manager. At least 8 and at most 256 characters, no other special requirements. But please don't be stupid and use a password manager.
</small> </small>
</div> </div>
<div class="form-group col-12"> <div class="form-group col-12">
......
...@@ -145,13 +145,18 @@ def send_passwordreset(loginname): ...@@ -145,13 +145,18 @@ def send_passwordreset(loginname):
send_mail(user.mail, msg) send_mail(user.mail, msg)
def send_mail(to_address, msg): def send_mail(to_address, msg):
server = smtplib.SMTP(host=current_app.config['MAIL_SERVER'], port=current_app.config['MAIL_PORT']) try:
if current_app.config['MAIL_USE_STARTTLS']: server = smtplib.SMTP(host=current_app.config['MAIL_SERVER'], port=current_app.config['MAIL_PORT'])
server.starttls() if current_app.config['MAIL_USE_STARTTLS']:
server.login(current_app.config['MAIL_USERNAME'], current_app.config['MAIL_PASSWORD']) server.starttls()
msg['From'] = current_app.config['MAIL_FROM_ADDRESS'] server.login(current_app.config['MAIL_USERNAME'], current_app.config['MAIL_PASSWORD'])
msg['To'] = to_address msg['From'] = current_app.config['MAIL_FROM_ADDRESS']
msg['Date'] = email.utils.formatdate(localtime=1) msg['To'] = to_address
msg['Message-ID'] = email.utils.make_msgid() msg['Date'] = email.utils.formatdate(localtime=1)
server.send_message(msg) msg['Message-ID'] = email.utils.make_msgid()
server.quit() server.send_message(msg)
server.quit()
return True
except SMTPException:
flash('Mail to "{}" could not be sent!'.format(to_address))
return False
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment