Closed CyrosX closed 9 months ago
Usually that report may coming as simple email. Or maybe not come. I do not know about standarts for it. Also see here https://github.com/ikvk/imap_tools/issues/155
I've tried this small code snippet: https://stackoverflow.com/a/5300759 and was able to get this kind of mail. Maybe this can be used for the implementation?
I will explore it
Example:
from imap_tools import MailBox, AND
with MailBox('imap.mail.com').login('test@mail.com', 'pwd') as mailbox:
for msg in mailbox.fetch():
for att in msg.attachments:
print(type(att.part))
print('-- filename', att.filename)
print('-- payload', att.payload)
print('-- payload decode', att.payload.decode())
I've tried it out, but these type of mails don't have any attachments. I cannot access the report.
msg.headers contains:
'content-type': ('multipart/report; report-type=delivery-status;\r\n\tboundary="**ALPHANUMERICAL_COMBINATION**/**MAILHOST**"',)
The report is separated from the text content with:
--**ALPHANUMERICAL_COMBINATION**/**MAILHOST**
The report starts like this:
Reporting-MTA: dns; [**MAILHOST**](**MAILHOST_WEBADDRESS**)
X-Postcow-Queue-ID: **ALPHANUMERICAL_COMBINATION**
X-Postcow-Sender: rfc822; [**MY_MAILADDRESS**](mailto:**MY_MAILADDRESS**)
Arrival-Date: Wed, 1 Nov 2023 05:14:30 +0100 (CET)
Final-Recipient: rfc822; [**ORIGINAL_RECIPIENT_MAILADDRESS**](mailto:**ORIGINAL_RECIPIENT_MAILADDRESS**)
....
Is there a possibility to view the whole raw message from a MailMessage object?
may you give me .eml example ?
Is it possible to get the message/delivery-status content of delivery error mail? The msg.text output is similar to this:
But it is missing the whole report, starting with:
Reporting-MTA: dns; XXX
msg.html / msg.attachment is empty.