05/29 Update invitation email sender based on domain name

This commit is contained in:
2026-05-29 10:02:21 -04:00
parent 38eb77a441
commit fbf2f61c6b
+9 -9
View File
@@ -162,7 +162,7 @@ def create():
log_action(ACTION_CREATE, 'User', user.id, user.username, log_action(ACTION_CREATE, 'User', user.id, user.username,
f'role=customer; email={user.email}; invite_sent=True') f'role=customer; email={user.email}; invite_sent=True')
_send_invite_email(user, token) _send_invite_email(user, token, base_url=request.host_url)
flash( flash(
f'Customer account created for {full_name}. ' f'Customer account created for {full_name}. '
@@ -174,23 +174,23 @@ def create():
return render_template('customers/invite.html', form=form) return render_template('customers/invite.html', form=form)
def _send_invite_email(user, token): def _send_invite_email(user, token, base_url=None):
"""Send the account setup email to a newly created customer.""" """Send the account setup email to a newly created customer."""
from flask import current_app, render_template_string from flask import current_app, render_template_string
from flask_mail import Message from flask_mail import Message
from app import mail from app import mail
from urllib.parse import urlparse
import threading import threading
if not current_app.config.get('MAIL_SERVER'): if not current_app.config.get('MAIL_SERVER'):
logger.warning('INVITE EMAIL SKIPPED | no MAIL_SERVER | user=%s', user.username) logger.warning('INVITE EMAIL SKIPPED | no MAIL_SERVER | user=%s', user.username)
return return
base_url = current_app.config.get('APP_BASE_URL', '').rstrip('/') effective_base = (base_url or current_app.config.get('APP_BASE_URL', '')).rstrip('/')
setup_link = f'{base_url}{url_for("customers.set_password", token=token)}' setup_link = f'{effective_base}{url_for("customers.set_password", token=token)}'
sender = current_app.config.get(
'MAIL_DEFAULT_SENDER', host = urlparse(effective_base).netloc or 'janitorialqc.local'
current_app.config.get('MAIL_USERNAME', 'noreply@janitorialqc.local'), sender = f'noreply@{host}'
)
html_body = render_template_string("""<!DOCTYPE html> html_body = render_template_string("""<!DOCTYPE html>
<html> <html>
@@ -270,7 +270,7 @@ def resend_invite(customer_id):
log_action(ACTION_UPDATE, 'User', customer.id, customer.username, log_action(ACTION_UPDATE, 'User', customer.id, customer.username,
f'invite resent by {current_user.username}') f'invite resent by {current_user.username}')
_send_invite_email(customer, token) _send_invite_email(customer, token, base_url=request.host_url)
flash(f'Invitation email resent to {customer.email}.', 'success') flash(f'Invitation email resent to {customer.email}.', 'success')
return redirect(url_for('customers.manage', customer_id=customer_id)) return redirect(url_for('customers.manage', customer_id=customer_id))