Compare commits
No commits in common. "a36f6d40e3fdbd9409862ae1a57c99d5824370ea" and "3b28920bf845dd193e2887dc92bb2a1f9bf348e4" have entirely different histories.
a36f6d40e3
...
3b28920bf8
2 changed files with 14 additions and 14 deletions
|
|
@ -38,9 +38,9 @@ dependencies = [
|
||||||
]
|
]
|
||||||
|
|
||||||
[project.urls]
|
[project.urls]
|
||||||
Documentation = "https://git.mra.sh/mra/carbon-copy#readme"
|
Documentation = "https://github.com/Micha Albert/carbon-copy#readme"
|
||||||
Issues = "https://git.mra.sh/mra/carbon-copy/issues"
|
Issues = "https://github.com/Micha Albert/carbon-copy/issues"
|
||||||
Source = "https://git.mra.sh/mra/carbon-copy"
|
Source = "https://github.com/Micha Albert/carbon-copy"
|
||||||
|
|
||||||
[tool.hatch.version]
|
[tool.hatch.version]
|
||||||
path = "src/carbon_copy/__about__.py"
|
path = "src/carbon_copy/__about__.py"
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import asyncio
|
||||||
import email as email_module
|
import email as email_module
|
||||||
from typing import List, Optional, Dict, Any
|
from typing import List, Optional, Dict, Any
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
|
|
@ -53,12 +54,16 @@ class EmailConfig:
|
||||||
if missing_fields:
|
if missing_fields:
|
||||||
raise ValueError(f"Missing required environment variables: {', '.join(missing_fields)}")
|
raise ValueError(f"Missing required environment variables: {', '.join(missing_fields)}")
|
||||||
|
|
||||||
if not smtp_port_str:
|
# Convert port strings to integers after validation
|
||||||
raise ValueError("SMTP_PORT must be set in the environment variables")
|
try:
|
||||||
self.smtp_port = int(smtp_port_str)
|
self.smtp_port = int(smtp_port_str)
|
||||||
if not imap_port_str:
|
except ValueError:
|
||||||
raise ValueError("IMAP_PORT must be set in the environment variables")
|
raise ValueError(f"SMTP_PORT must be a valid integer, got: {smtp_port_str}")
|
||||||
self.imap_port = int(imap_port_str)
|
|
||||||
|
try:
|
||||||
|
self.imap_port = int(imap_port_str)
|
||||||
|
except ValueError:
|
||||||
|
raise ValueError(f"IMAP_PORT must be a valid integer, got: {imap_port_str}")
|
||||||
|
|
||||||
|
|
||||||
class EmailMessage:
|
class EmailMessage:
|
||||||
|
|
@ -112,9 +117,6 @@ class SMTPClient:
|
||||||
else:
|
else:
|
||||||
msg = MIMEText(content, "plain")
|
msg = MIMEText(content, "plain")
|
||||||
|
|
||||||
if not from_email:
|
|
||||||
raise ValueError("From email must be provided or set in configuration")
|
|
||||||
|
|
||||||
msg["Subject"] = subject
|
msg["Subject"] = subject
|
||||||
msg["From"] = from_email
|
msg["From"] = from_email
|
||||||
msg["To"] = to_email
|
msg["To"] = to_email
|
||||||
|
|
@ -133,8 +135,6 @@ class SMTPClient:
|
||||||
port=self.config.smtp_port,
|
port=self.config.smtp_port,
|
||||||
use_tls=self.config.smtp_use_tls
|
use_tls=self.config.smtp_use_tls
|
||||||
) as smtp:
|
) as smtp:
|
||||||
if not self.config.smtp_username or not self.config.smtp_password:
|
|
||||||
raise ValueError("SMTP username and password must be set in configuration")
|
|
||||||
await smtp.login(self.config.smtp_username, self.config.smtp_password)
|
await smtp.login(self.config.smtp_username, self.config.smtp_password)
|
||||||
await smtp.send_message(msg)
|
await smtp.send_message(msg)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue