Skip to content

Commit

Permalink
Merge branch 'EmailInfra' of https://github.com/koesterlab/remail int…
Browse files Browse the repository at this point in the history
…o EmailInfra
  • Loading branch information
JNAOB committed Nov 29, 2024
2 parents f8102cc + 627df2c commit 06ca25c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 12 deletions.
29 changes: 19 additions & 10 deletions EMailService.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ def send_email(self, email:Email) -> bool:
msg.set_content(email.body)

#attachment
with open(email.attachments[0].filename, "rb") as f:
file_data = f.read()
msg.add_attachment(file_data, maintype = "text", subtype = "plain", filename = "test.txt")
for att in email.attachments:
with open(att.filename, "rb") as f:
file_data = f.read()
msg.add_attachment(file_data, maintype = "text", subtype = "plain", filename = "test.txt")

#connect/authenticate
smtp_server = SMTP_SSL(self.SMTP_HOST, port = SMTP_SSL_PORT)
smtp_server.set_debuglevel(1)
smtp_server.login(SMTP_USER, SMTP_PASS)
smtp_server.send_message(msg)

Expand All @@ -112,7 +112,10 @@ def delete_email(self, uid:int) -> bool:
def get_emails(self, date : datetime = None)->list[Email]:
listofMails = []
self.IMAP.select_folder("INBOX")
messages_ids = self.IMAP.search(["ALL"])
if date != None:

Check failure on line 115 in EMailService.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E711)

EMailService.py:115:20: E711 Comparison to `None` should be `cond is not None`
messages_ids = self.IMAP.search([u'SINCE',date])
else:
messages_ids = self.IMAP.search(["ALL"])
for msgid,message_data in self.IMAP.fetch(messages_ids,["RFC822","UID"]).items():
email_message = email.message_from_bytes(message_data[b"RFC822"])
Uid = message_data.get(b"UID")
Expand Down Expand Up @@ -157,6 +160,12 @@ def get_emails(self, date : datetime = None)->list[Email]:
else:
body = email_message.get_payload(decode=True)

#hier fehlt noch das date

in_reply_to = email_message["in_reply_to"]
print(in_reply_to)


listofMails += [create_email(
uid = Uid,
sender = email_message["from"],
Expand Down Expand Up @@ -293,19 +302,19 @@ def imap_test():
imap = ImapProtocol()
test = Email(

subject="Hellololo",
body="World i wanna finally go home today!!!!",
subject="Hellololololo",
body="Test time!!",
recipients=[EmailReception(contact=(Contact(email_address ="praxisprojekt-remail@uni-due.de")), kind=RecipientKind.to),EmailReception(contact=(Contact(email_address ="toadbella@gmail.com")), kind=RecipientKind.to)],
attachments=[Attachment(filename=r"C:\Users\toadb\Documents\ReinventingEmail\test.txt")])

#attachments=[Attachment(filename=r"C:\Users\toadb\Documents\ReinventingEmail\test.txt")])
)
print("IMAP Logged_in: ",imap.logged_in)
imap.login("thatchmilo35@gmail.com","mgtszvrhgkphxghm")
print("IMAP Logged_in: ",imap.logged_in)

imap.send_email(test)
print("sent?")

listofmails = imap.get_emails()
#listofmails = imap.get_emails()
#print("body" ,listofmails[0].body,"id",listofmails[0].id )

imap.logout()
Expand Down
Binary file modified __pycache__/email2.cpython-312.pyc
Binary file not shown.
5 changes: 3 additions & 2 deletions email2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import List, Optional
import sqlalchemy
from sqlmodel import Field, SQLModel, Relationship, Session, create_engine, select

from datetime import datetime

def id_field(table_name: str):
sequence = sqlalchemy.Sequence(f"{table_name}_id_seq")
Expand Down Expand Up @@ -52,4 +52,5 @@ class Email(SQLModel, table=True):
subject: str
body: str
attachments: List[Attachment] = Relationship(back_populates="email")
recipients: List[EmailReception] = Relationship(back_populates="email")
recipients: List[EmailReception] = Relationship(back_populates="email")
date: datetime

0 comments on commit 06ca25c

Please sign in to comment.