I just want to create some inbound emails from my inbox.
from exchangelib import Credentials, Account, Configuration, DELEGATE
from pathlib import Path
import dotenv
import argparse
import os
import proteus
from proteus import Model
....
# Modell für eingehende Mails laden
InboundEmail = Model.get('inbound.email')
InboundEmailInbox = Model.get('inbound.email.inbox')
try:
inbox, = InboundEmailInbox.find([('identifier', '=', os.getenv('tryton_inbox'))])
except Exception as e:
print(f"Error finding inbox: {e}")
raise SystemExit("script stopped")
for mail in folder_in.all().order_by('-datetime_received')[:10]:
print(f"Processing mail: {mail.subject} from {mail.sender.email_address} received at {mail.datetime_received}")
try:
# Mail in trytond speichern
inbound_mail = InboundEmail()
inbound_mail.inbox = inbox
inbound_mail.data = mail.mime_content
inbound_mail.data_type = 'raw'
inbound_mail.save()
print(f"Mail saved in trytond with id: {inbound_mail.id}")
# Mail in den erledigt Ordner verschieben
mail.move(folder_out)
print("Mail moved to 'Lieferantenrechnungen-erledigt' folder")
except Exception as e:
print(f"Error processing mail: {e}")
On save I receive the error
Error processing email: <Fault 1: ‘A value is required for the “Data Type” field in “Incoming Email”. - ’>
I tried that one too, but receiving ‘\n\n413 Request Entity Too Large\nRequest Entity Too Large\nThe data value transmitted exceeds the capacity limit.\n’
from exchangelib import Credentials, Account, Configuration, DELEGATE
from pathlib import Path
import dotenv
import argparse
import os
import proteus
import requests
from proteus import Model
from email.message import EmailMessage
def get_message():
message = EmailMessage()
message['From'] = "John Doe <john.doe@example.com>"
message['To'] = (
"Michael Scott <michael@example.com>, pam@example.com")
message['Cc'] = 'jim@example.com'
message['Subject'] = "The office"
message.set_content("Hello")
message.add_attachment(
b'bin', maintype='application', subtype='octet-stream',
filename='data.bin')
return message
if __name__ == "__main__":
....
url = f"{os.getenv('tryton_protocol')}://{os.getenv('tryton_server')}:{os.getenv('tryton_port')}/{os.getenv('tryton_database')}/inbound_email/inbox/{os.getenv('tryton_inbox')}"
for mail in folder_in.all().order_by('-datetime_received')[:10]:
print(f"Processing mail: {mail.subject} from {mail.sender.email_address} received at {mail.datetime_received}")
try:
# Mail in trytond speichern
response = requests.post(
url,
data=get_message().as_bytes(),
headers={
"Content-Type": "message/rfc822",
},
)
print(response.status_code)
except Exception as e:
print(f"Error processing mail: {e}")
b’From: John Doe john.doe@example.com\nTo: Michael Scott michael@example.com, pam@example.com\nCc: jim@example.com\nSubject: The office\nMIME-Version: 1.0\nContent-Type: multipart/mixed; boundary=“===============0098447207566907498==”\n\n–===============0098447207566907498==\nContent-Type: text/plain; charset=“utf-8”\nContent-Transfer-Encoding: 7bit\n\nHello\n\n–===============0098447207566907498==\nContent-Type: application/octet-stream\nContent-Transfer-Encoding: base64\nContent-Disposition: attachment; filename=“data.bin”\nMIME-Version: 1.0\n\nYmlu\n\n–===============0098447207566907498==–\n’