【问题标题】:Attaching Files to Email in App Engine?在 App Engine 中将文件附加到电子邮件?
【发布时间】:2010-08-03 07:26:05
【问题描述】:

如何使用谷歌应用引擎 (Python) 将位于 Web URL 上的文件附加到电子邮件?

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

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

【问题讨论】:

    标签: google-app-engine email url attachment


    【解决方案1】:

    要发送附件,您必须使用包含文件名和文件内容的二值元组列表填充电子邮件的附件字段。来自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)])
    

    【讨论】:

    • 如果您已经将 PDF 上传到项目中,如何添加附件?
    猜你喜欢
    • 2014-06-25
    • 2016-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-21
    • 2014-02-18
    • 2020-11-21
    相关资源
    最近更新 更多