Notification Mail püpscher
This commit is contained in:
parent
14244e2f48
commit
331ffcd10c
@ -6,6 +6,7 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="font-family: Helvetica, sans-serif; font-size: 16px; vertical-align: top; border-radius: 4px; text-align: center; background-color: [[color]];" valign="top" align="center" bgcolor="[[color]]">
|
<td style="font-family: Helvetica, sans-serif; font-size: 16px; vertical-align: top; border-radius: 4px; text-align: center; background-color: [[color]];" valign="top" align="center" bgcolor="[[color]]">
|
||||||
|
<span style="font-size:14px; color: #ffffff;">[[notification_text]]</span><br/>
|
||||||
<a href="[[link]]" target="_blank" style="border: solid 2px [[color]]; border-radius: 4px; box-sizing: border-box; cursor: pointer; display: inline-block; font-size: 16px; font-weight: bold; margin: 0; padding: 12px 24px; text-decoration: none; text-transform: capitalize; background-color: [[color]]; border-color: [[color]]; color: #ffffff;">[[text]]</a>
|
<a href="[[link]]" target="_blank" style="border: solid 2px [[color]]; border-radius: 4px; box-sizing: border-box; cursor: pointer; display: inline-block; font-size: 16px; font-weight: bold; margin: 0; padding: 12px 24px; text-decoration: none; text-transform: capitalize; background-color: [[color]]; border-color: [[color]]; color: #ffffff;">[[text]]</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@ -77,6 +77,9 @@ def SendEmails(email_dict):
|
|||||||
This function sends emails to all users in the emaildict
|
This function sends emails to all users in the emaildict
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
|
pooledConnection = getPoolConnection()
|
||||||
|
commands = pydapper.using(pooledConnection)
|
||||||
|
|
||||||
conn = smtplib.SMTP(defs.email_credentials["server"], defs.email_credentials["port"])
|
conn = smtplib.SMTP(defs.email_credentials["server"], defs.email_credentials["port"])
|
||||||
conn.set_debuglevel(1)
|
conn.set_debuglevel(1)
|
||||||
conn.ehlo()
|
conn.ehlo()
|
||||||
@ -113,8 +116,32 @@ def SendEmails(email_dict):
|
|||||||
|
|
||||||
# We want to show the following information for each notification:
|
# We want to show the following information for each notification:
|
||||||
# Ship-name, Arr/Dep/Shift, ETA/ETD, berth
|
# Ship-name, Arr/Dep/Shift, ETA/ETD, berth
|
||||||
|
sentinel = object()
|
||||||
|
shipcall = commands.query_single_or_default("SELECT * FROM shipcall WHERE id = ?id?", sentinel, model=model.Shipcall, param={"id":notification.shipcall_id})
|
||||||
|
if shipcall is sentinel:
|
||||||
|
logging.error(f"Shipcall with id {notification.shipcall_id} not found")
|
||||||
|
continue
|
||||||
|
shipcall_type = defs.shipcall_types[shipcall.type]
|
||||||
|
eta_text = shipcall.eta.strftime("%d.%m.%Y %H:%M") if shipcall.type == 1 else shipcall.etd.strftime("%d.%m.%Y %H:%M")
|
||||||
|
|
||||||
|
ship = commands.query_single_or_default("SELECT * FROM ship WHERE id = ?id?", sentinel, model=model.Ship, param={"id":shipcall.ship_id})
|
||||||
|
if ship is sentinel:
|
||||||
|
logging.error(f"Ship with id {shipcall.ship_id} not found")
|
||||||
|
continue
|
||||||
|
berth_id = shipcall.arrival_berth_id if shipcall.type == 1 else shipcall.departure_berth_id
|
||||||
|
berth = commands.query_single_or_default("SELECT * FROM berth WHERE id = ?id?", sentinel, model=model.Berth, param={"id":berth_id})
|
||||||
|
berth_text = ""
|
||||||
|
if berth is not sentinel:
|
||||||
|
berth_text = berth.name
|
||||||
|
times = commands.query_single_or_default("SELECT * FROM times WHERE shipcall_id = ?id? and participant_type = 8", sentinel, model=model.Times, param={"id":notification.shipcall_id})
|
||||||
|
if times is not sentinel:
|
||||||
|
eta_text = times.eta_berth.strftime("%d.%m.%Y %H:%M") if shipcall.type == 1 else times.etd_berth.strftime("%d.%m.%Y %H:%M")
|
||||||
|
|
||||||
|
text = f"{ship.name} ({shipcall_type}) - {eta_text} - {berth_text}"
|
||||||
|
|
||||||
|
element = element.replace("[[text]]", text)
|
||||||
|
element = element.replace("[[notification_text]]", message_type["msg_text"])
|
||||||
|
|
||||||
element = element.replace("[[text]]", message_type["msg_text"])
|
|
||||||
replacement += element
|
replacement += element
|
||||||
|
|
||||||
body = body.replace("[[NOTIFICATION_ELEMENTS]]", replacement)
|
body = body.replace("[[NOTIFICATION_ELEMENTS]]", replacement)
|
||||||
|
|||||||
Reference in New Issue
Block a user