admin管理员组

文章数量:1123687

I have email addresses stored in AWS Workmail and I want to use them with an AWS Lambda in order to send mails to different destination email addresses. I managed to send mails however only the mails WITHOUT attachments are visibile in the sent folder (named Sent Items in AWS Workmail). This is a huge problem for use because we need to list all sent mails with and without attachments.

Here is my code in Python (I installed the libraries exchangelib, pytzand lxml), can you tell me what I am missing or is there another way to do so:

import time
from exchangelib.items import (
    SEND_TO_ALL_AND_SAVE_COPY,
)
from exchangelib import Account, Credentials, DELEGATE, Configuration, Message, FileAttachment, UTC, UTC_NOW


# Specify my AWS Wormail email address and its password
email_address = "[email protected]"
password = "xxxxxxx"


# Set credentials
credentials = Credentials(username=email_address, password=password)
config = Configuration(
        credentials=credentials, 
        service_endpoint=f'.asmx',
        auth_type='basic'
)
account = Account(primary_smtp_address=email_address, autodiscover=False, config=config, access_type=DELEGATE)


# Prepare and send the mail to send with an attachment
message = Message(
    account=account,
    subject="test attachment in sent",
    folder=account.sent,
    body="some test",
    to_recipients=[
        "[email protected]" # A destination email address
    ],
)
with open("my-file.txt", "rb") as file:
    content = file.read()
message.attach(
    FileAttachment(name="my-file.txt", content=content)
)
message.send_and_save()
print(message)
time.sleep(30)
print("######################")


# List the mails sent
sent_emails = account.sent.all()
for sent_mail in sent_emails:
    print("Subject:", sent_mail.subject)
    print("Sender:", sent_mail.sender)
    print("Recipients:", sent_mail.to_recipients)
    print("Attachments:", sent_mail.attachments)
    print("----------")
```

本文标签: