""" Email service functions for the Flask job application system. """ from datetime import datetime from flask import url_for, current_app from flask_mail import Message from app import mail def send_resume_email(email, session_id, job_name): """Send email with resume link""" resume_link = url_for('resume_application', session_id=session_id, _external=True) subject = f"Ihre Bewerbung bei {current_app.config['COMPANY_NAME']} - Link zum Fortsetzen" body = f"""Guten Tag, vielen Dank für Ihr Interesse an der Position "{job_name}" bei {current_app.config['COMPANY_NAME']}. Sie können Ihre Bewerbung jederzeit über den folgenden Link fortsetzen: {resume_link} Dieser Link bleibt gültig und Sie können Ihre Bewerbung jederzeit bearbeiten. Mit freundlichen Grüßen {current_app.config['COMPANY_NAME']} """ try: msg = Message(subject=subject, recipients=[email], body=body) mail.send(msg) return True except Exception as e: current_app.logger.error(f"Failed to send email: {e}") return False def send_hr_notification(session_id, app_data): """Send HR notification email when application is submitted""" if not current_app.config.get('HR_EMAIL'): current_app.logger.warning("HR_EMAIL not configured, skipping HR notification") return False # Build application URL application_url = f"{current_app.config['APPLICATION_URL_BASE']}/application/{session_id}/" # Get personal info personal_info = app_data.get('personal_info', {}) firstname = personal_info.get('firstname', 'N/A') name = personal_info.get('name', 'N/A') email = app_data.get('email', 'N/A') job_name = app_data.get('job_name', 'N/A') file_count = len(app_data.get('uploaded_files', [])) # Format timestamp submitted_at = app_data.get('submitted_at', datetime.now().isoformat()) try: timestamp = datetime.fromisoformat(submitted_at).strftime('%d.%m.%Y %H:%M') except (ValueError, TypeError): timestamp = submitted_at subject = f"Neue Bewerbung eingegangen: {job_name}" body = f"""Sehr geehrtes HR-Team, es ist eine neue Bewerbung eingegangen: Position: {job_name} Name: {firstname} {name} E-Mail: {email} Eingereicht am: {timestamp} Anzahl der hochgeladenen Dokumente: {file_count} Sie können die vollständige Bewerbung hier einsehen: {application_url} Mit freundlichen Grüßen, Ihr Bewerbungssystem """ try: msg = Message(subject=subject, recipients=[current_app.config['HR_EMAIL']], body=body) mail.send(msg) return True except Exception as e: current_app.logger.error(f"Failed to send HR notification email: {e}") return False