如何将win32com.client添加为Docker映像的需求。TXT的依赖性?

发布于 2025-02-07 01:08:49 字数 1251 浏览 2 评论 0原文

我正在构建一个带有Python脚本的容器,该容器使用Outlook发送电子邮件。在构建过程中,我很难将Win32COM添加到我的容器中。它给出了错误没有名为“ Win32COM”的模块。有人可以帮助我找不到在线解决方案。 是我的代码:

电子邮件

import win32com.client as win32
# import json
from fastapi import FastAPI

app = FastAPI() 


@app.get("/")
async def root():
    outlook = win32.Dispatch('outlook.application')
    mail = outlook.CreateItem(0)
    mail.To = '[email protected]'
    mail.Subject = 'Testing Email Through Outlook'
    mail.Body = 'This shouldnot have taken this long'
    mail.HTMLBody = '<h2>Hello World</h2>' #this field is optional

        # To attach a file to the email (optional):
    attachment  = "find.json"
    mail.Attachments.Add(attachment)

    mail.Send()

certifi==2020.12.5
click==7.1.2
fastapi==0.63.0
h11==0.11.0
starlette==0.13.6
uvicorn==0.13.3
pywin32==304
win32-setctime==1.0.3
win32com 
pypiwin32

FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7

ADD find.json .
ADD email.py .

COPY requirements.txt .
RUN pip --no-cache-dir install -r requirements.txt

I am building a container with python script that sends an email using outlook. I am having trouble adding win32com to my container in the build process. It gives the error No module named 'win32com'. Can someone please help I can't find a solution online. Here's my code:

email.py

import win32com.client as win32
# import json
from fastapi import FastAPI

app = FastAPI() 


@app.get("/")
async def root():
    outlook = win32.Dispatch('outlook.application')
    mail = outlook.CreateItem(0)
    mail.To = '[email protected]'
    mail.Subject = 'Testing Email Through Outlook'
    mail.Body = 'This shouldnot have taken this long'
    mail.HTMLBody = '<h2>Hello World</h2>' #this field is optional

        # To attach a file to the email (optional):
    attachment  = "find.json"
    mail.Attachments.Add(attachment)

    mail.Send()

requirements.txt

certifi==2020.12.5
click==7.1.2
fastapi==0.63.0
h11==0.11.0
starlette==0.13.6
uvicorn==0.13.3
pywin32==304
win32-setctime==1.0.3
win32com 
pypiwin32

Dockerfile

FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7

ADD find.json .
ADD email.py .

COPY requirements.txt .
RUN pip --no-cache-dir install -r requirements.txt

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七颜 2025-02-14 01:08:49

我想您可以得到的最接近的是在容器中安装葡萄酒,然后在葡萄酒下执行代码。

您将需要在先验之前安装与葡萄酒的Python。

Ready Docker Images

无论如何,我认为它不会用于您的目的,如果在容器中存在,则Outlook无法正确配置。

I guess the closest you can get is installing wine inside the container and executing your code under wine.

You will need to install python with wine prior.

There are wine ready docker images.

In any case I do not think it is going to work for your purpose, Outlook if exists in the container will not be properly configured.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文