-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,14 +3,14 @@ | |
import sys | ||
import signal | ||
from pathlib import Path | ||
|
||
# Ensure the parent directory is in sys.path so relative imports work. | ||
base_dir = Path(__file__).parent | ||
if base_dir not in sys.path: | ||
sys.path.append(str(base_dir)) | ||
from common.paths import backend_dir, venv_dir, cert_dir | ||
from common.config import logging_config | ||
from backend.utils import get_env_key | ||
from common.mail import send | ||
|
||
# check environment | ||
from backend.env import check_env | ||
|
@@ -48,6 +48,7 @@ def cleanup(): | |
|
||
# Log connection details | ||
logger.info(f"You can access pAI-OS at https://{host}:{port}.") | ||
#asyncio.run(send("[email protected]", "pAI-OS started up", f"You can access pAI-OS at https://{host}:{port}.")) | ||
logger.info("Bypass certificate warnings if using self-signed certificates.") | ||
|
||
# Run the app | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import aiosmtplib | ||
import secrets | ||
from email.mime.multipart import MIMEMultipart | ||
from email.mime.text import MIMEText | ||
from .utils import get_env_key # Assuming get_env_key is in utils module | ||
|
||
async def send(to, subject, body_text, body_html = None): | ||
# sends mail via SMTP in text and/or html format | ||
# asyncio.run(send("[email protected]", "pAI-OS started up", f"You can access pAI-OS at https://{host}:{port}.")) | ||
|
||
# Retrieve SMTP server details from environment variables | ||
smtp_host = get_env_key('PAIOS_SMTP_HOST', 'localhost') | ||
smtp_port = get_env_key('PAIOS_SMTP_PORT', '587') # Default SMTP port for STARTTLS | ||
smtp_from = get_env_key('PAIOS_SMTP_FROM', 'paios@localhost') | ||
smtp_user = get_env_key('PAIOS_SMTP_USER', 'paios@localhost') | ||
smtp_pass = get_env_key('PAIOS_SMTP_PASS', secrets.token_urlsafe(32)) | ||
|
||
# Create a MIME message | ||
msg = MIMEMultipart('alternative') | ||
msg['Subject'] = subject | ||
msg['From'] = smtp_from | ||
msg['To'] = to | ||
|
||
# Ensure body_html is not None | ||
if body_html is None: | ||
body_html = body_text # Fallback to plain text if HTML is not provided | ||
|
||
# Attach both plain text and HTML parts | ||
part1 = MIMEText(body_text, 'plain') | ||
part2 = MIMEText(body_html, 'html') | ||
msg.attach(part1) | ||
msg.attach(part2) | ||
|
||
# Connect to the SMTP server and send the email | ||
try: | ||
await aiosmtplib.send( | ||
msg, | ||
hostname=smtp_host, | ||
port=smtp_port, | ||
start_tls=True, | ||
username=smtp_user, | ||
password=smtp_pass, | ||
) | ||
except Exception as e: | ||
print(f"Failed to send email: {e}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
# common requirements | ||
cryptography | ||
aiosmtplib |