Skip to content

Commit

Permalink
added try catch to mail gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
clemenstyp committed Feb 20, 2024
1 parent a9df3e5 commit 232ba8b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 29 deletions.
14 changes: 9 additions & 5 deletions SnackBar.py
Expand Up @@ -10,6 +10,7 @@
from hashlib import md5
from math import sqrt
from collections import Counter
import traceback

import flask_login as loginflask
import schedule
Expand Down Expand Up @@ -676,14 +677,19 @@ class MyPaymentModelView(ModelView):
can_export = True
form_excluded_columns = 'date'
export_types = ['csv']
column_descriptions = dict()
column_labels = dict(user='Name')
column_default_sort = ('date', True)
column_filters = ('user', 'amount', 'date')
list_template = 'admin/custom_list.html'

# noinspection PyMethodMayBeStatic,PyUnusedLocal
def date_format(self, context, model, name):
field = getattr(model, name)
return field.strftime('%Y-%m-%d %H:%M')
if field is not None:
return field.strftime('%Y-%m-%d %H:%M')
else:
return ""

column_formatters = dict(date=date_format)

Expand Down Expand Up @@ -893,9 +899,7 @@ def index(self):
return redirect(url_for('initial'))

init_login()


admin = Admin(app, name='SnackBar Admin Page', index_view=MyAdminIndexView(), base_template='my_master.html')
admin = Admin(app, name='SnackBar Admin Page', index_view=MyAdminIndexView(), base_template='my_master.html', template_mode='bootstrap2')
admin.add_view(MyBillView(name='Bill', endpoint='bill'))
# admin.add_view(MyAccountingView(name='Accounting', endpoint='accounting'))
admin.add_view(MyPaymentModelView(Inpayment, db.session, 'Inpayment'))
Expand Down Expand Up @@ -1613,7 +1617,7 @@ def api_buy():
response = Response(json.dumps(
{"data": "",
"status": "error",
"message": f"Some unknown error occured: Exception:{e}",
"message": f"Some unknown error occured: Exception: {''.join(traceback.format_exception(e))}",
}), mimetype='application/json')
response.status_code = 400
return response
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.yaml
Expand Up @@ -16,4 +16,5 @@ services:
- ./data:/app/data
- /etc/localtime:/etc/localtime:ro
environment:
SNACKBAR_URL_PREFIX: '/demo'
SNACKBAR_URL_PREFIX: '/demo'
SNACKBAR_HOST: 0.0.0.0
2 changes: 1 addition & 1 deletion flaskrun.py
Expand Up @@ -81,7 +81,7 @@ def flaskrun(app, options=None):
logging.getLogger("werkzeug").setLevel(logging.WARNING)
else:
logging.getLogger("werkzeug").setLevel(logging.DEBUG)

app.run(
debug=options.debug,
host=options.host,
Expand Down
43 changes: 23 additions & 20 deletions sendEmail.py
Expand Up @@ -24,26 +24,29 @@ def __init__(self, subject, recipients):
self.servername = ''

def send(self):
msg = MIMEMultipart('mixed')
msg['From'] = self.sendername
msg['Subject'] = self.subject
msg['To'] = ", ".join(self.recipients) # to must be array of the form ['mailsender135@gmail.com']
# msg.preamble = "Das ist eine Präambel"
# check if there are attachments if yes, add them
if self.attachments:
self.attach(msg)
# add html body after attachments
msg.attach(MIMEText(self.htmlbody, 'html'))
if msg.get('Date', None) is None:
msg['Date'] = email.utils.formatdate()
# send
s = smtplib.SMTP(self.servername)
# s.starttls()
# s.login(self.sender, self.senderpass)
s.sendmail(self.sender, self.recipients, msg.as_string())
# test
# print(msg)
s.quit()
try:
msg = MIMEMultipart('mixed')
msg['From'] = self.sendername
msg['Subject'] = self.subject
msg['To'] = ", ".join(self.recipients) # to must be array of the form ['mailsender135@gmail.com']
# msg.preamble = "Das ist eine Präambel"
# check if there are attachments if yes, add them
if self.attachments:
self.attach(msg)
# add html body after attachments
msg.attach(MIMEText(self.htmlbody, 'html'))
if msg.get('Date', None) is None:
msg['Date'] = email.utils.formatdate()
# send
s = smtplib.SMTP(self.servername)
# s.starttls()
# s.login(self.sender, self.senderpass)
s.sendmail(self.sender, self.recipients, msg.as_string())
# test
# print(msg)
s.quit()
except Exception as e:
pass

def htmladd(self, html):
self.htmlbody = self.htmlbody + '<p></p>' + html
Expand Down
5 changes: 3 additions & 2 deletions templates/index.html
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en-US">

<head>
Expand All @@ -12,12 +12,13 @@
<meta name="apple-mobile-web-app-title" content="Snackbar">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="apple-touch-icon" href="{{url_for('static', filename='app_icon.png')}}">

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.2/semantic.min.css"/>

<!-- teh stay_standalone javascript must be the first script in your <head> -->
<script src="{{url_for('static', filename='stay_standalone.js')}}" type="text/javascript"></script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.2/semantic.min.js"></script>

<!--<link rel="stylesheet" href="{{url_for('static', filename='semantic/semantic.min.css')}}"/>-->
Expand Down

0 comments on commit 232ba8b

Please sign in to comment.