如何将win32com.client添加为Docker映像的需求。TXT的依赖性?
我正在构建一个带有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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想您可以得到的最接近的是在容器中安装葡萄酒,然后在葡萄酒下执行代码。
您将需要在先验之前安装与葡萄酒的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.