Commit aa4ff70c authored by Benjamin Krause's avatar Benjamin Krause
Browse files

Adjust mail provider class

parent de0bb236
......@@ -2,6 +2,7 @@ import email
import imaplib
import smtplib
from email.message import EmailMessage
from enum import Enum
from pydantic import BaseModel
......@@ -10,17 +11,26 @@ from app.user import User
from app.utils import subject_identifier
class Encryption(Enum):
SSL_TLS = "ssl_tls"
STARTTLS = "starttls"
class MailProvider(BaseModel):
name: str
base_url: str
imap_url: str
imap_port: int = 993
imap_encryption: Encryption = Encryption.STARTTLS
smtp_url: str
smtp_port: int
smtp_port: int = 587
smtp_encryption: Encryption = Encryption.STARTTLS
def send_mail(self, from_user: User, to_user: User, message: EmailMessage):
with smtplib.SMTP(self.smtp_url, self.smtp_port) as server:
server.login(from_user.mail, from_user.password)
server.sendmail(from_user.mail, to_user.mail, message.as_string())
return True
......@@ -54,7 +64,9 @@ class MailProvider(BaseModel):
def imap_login(self, user: User) -> imaplib.IMAP4_SSL:
imap = imaplib.IMAP4_SSL(self.imap_url)
imap = imaplib.IMAP4_SSL(self.imap_url, self.smtp_port)
imap.login(user.mail, user.password)
return imap
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment