©2009 Google -
Code 主页 -
站点服务条款 -
隐私政策 -
站点目录
Google Code 有以下版本:
English -
Español -
日本語 -
한국어 -
Português -
Pусский -
中文(简体) -
中文(繁體)
电子邮件可以包含文件附件。电子邮件的 [attachments] 字段接受二值元组列表(每个附件对应一个元组)。元组的第一个元素是用于邮件中的附件的文件名,第二个元素是数据(采用字节字符串形式)。
from google.appengine.api import mail
from google.appengine.ext import db
class DocFile(db.Model):
doc_name = StringProperty()
doc_file = BlobProperty()
q = db.GqlQuery("SELECT * FROM DocFile WHERE doc_name = :1", myname)
results = q.fetch(1)
if results:
doc = results[0]
mail.send_mail(sender="support@example.com",
to="Albert Johnson <Albert.Johnson@example.com>",
subject="The doc you requested",
body="""
Attached is the document file you requested.
The example.com Team
""",
attachments=[(doc.doc_name, doc.doc_file)])
只允许某些类型的文件作为附件。附件的文件名则说明该文件的类型。
为了安全起见,附加到电子邮件的文件必须是以下允许的文件类型,并且文件名必须以与文件类型对应的扩展名结尾。附件以文件扩展名决定的 MIME 类型发送。
以下是允许作为电子邮件文件附件的 MIME 类型及其对应的文件扩展名列表。
| MIME 类型 | 文件扩展名 |
|---|---|
| 图像/x-ms-bmp | bmp |
| 文本/css | css |
| 文本/逗号分隔值 | csv |
| 图像/gif | gif |
| 文本/html | htm、html |
| 图像/jpeg | jpeg、jpg、jpe |
| 应用程序/pdf | |
| 图像/png | png |
| 应用程序/rss+xml | rss |
| 文本/plain | text、txt、asc、diff、pot |
| 图像/tiff | tiff、tif |
| 图像/vnd.wap.wbmp | wbmp |