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
, pytz
and 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("----------")
```
本文标签:
版权声明:本文标题:amazon web services - Mails sent with attachments, using the library exchangelib in Python, are NOT visible in the sent folder - 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736587916a1945036.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论