gpt4 book ai didi

google-app-engine - 在 App Engine 中将文件附加到电子邮件?

转载 作者:太空宇宙 更新时间:2023-11-03 15:28:24 25 4
gpt4 key购买 nike

如何使用 Google App Engine (Python) 将位于 Web URL 上的文件附加到电子邮件?

我的文件位于:http://www.abc.com/files/file.pdf

我想将其附加到电子邮件中并将其发送给 App Engine 上的用户。我该怎么做?

最佳答案

要发送附件,您必须使用包含文件名和文件内容的双值无元组列表填充电子邮件的附件字段。来自 here

from google.appengine.api import urlfetch
from google.appengine.api import mail

url = "http://www.abc.com/files/file.pdf"
result = urlfetch.fetch(url)

if result.status_code == 200:
document = result.content

mail.send_mail(sender="youremail@yourdomain.com",
to="receiver@hisdomain.com",
subject="The file you wanted",
body="Here is the file you wanted",
attachments=[("The file name.pdf", document)])

关于google-app-engine - 在 App Engine 中将文件附加到电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3394397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com