调用用户的标准邮件客户端 [英] invoke user's standard mail client
问题描述
您好,
从
Python程序启动用户标准邮件客户端的最简单方法是创建mailto:URL和推出
webbrowser:
def mailto_url(to = None,subject = None,body = None,cc = None):
"""
将内容编码为mailto链接,如
http://www.faqs.org/rfcs/rfc2368.html
部分取自
http://selfhtml.teamone.de/html/verweise/email.htm
"""
url =" mailto:" + urllib.quote(to.strip()," @,")
sep ="?"
if cc:
url + = sep +" cc =" + urllib.quote(cc," @,")
sep ="&"
if subject:
url + = sep +" subject =" + urllib.quote(subject,"")
sep ="&"
if body:
#另请注意邮件正文中的换行必须是用%0D%0A编码的
#。 (RFC 2368)
body =" \\\\ n" .join(body.splitlines())
url + = sep +" body =" + urllib.quote(body,"")
sep ="&"
return url
导入webbrowser
url = mailto_url(...)
webbrowser.open(url,new = 1)
(摘录来自 http://svn.berlios.de/wsvn/lino/trun...ile&rev=0&sc=0 )
但是此方法有限:您无法指定要附加的文件
到邮件。我想如果正文文本
太复杂会有问题。
有人知道更好的方法吗?
应该至少可以在Windows上使用,因为Acrobat Reader能够做到这一点。
提前感谢任何提示!
Luc Saffre
lu ******** @ gmail.com 写道:
启动用户标准的最简单方法来自一个
Python程序的邮件客户端是通过创建一个mailto:URL并启动
webbrowser:
[...剪辑代码...]
但是这种方法是有限的:你不能指定要附加的文件
到邮件。我想如果正文文本
过于复杂会有问题。
有人知道更好的方法吗?
至少在Windows上应该可以,因为Acrobat Reader是
能够做到这一点。
我要伸出脖子说:我怀疑
,如果有一个公认的,批准的方法。那个
会要求每个电子邮件客户端都有办法接受一个命令,即打开一个新的
电子邮件并将其放入,这个,以及这个领域,
那个空间和那个附件。我能想到的唯一的东西就是你所提到的mailto:
协议,但是根据它的RFC
http://www.faqs.org/rfcs/rfc2368.html
允许的唯一字段是标题和特殊的
body的情况正如你所指出的那样,很难用于嵌入式附件。
我会想象Acrobat必须特殊情况
已知的电子邮件客户端,可能不会为一些不起眼的客户工作。例如,Thunderbird好像(没有尝试过)允许附件:
http://www.mozilla.org/docs/command-line-args.html
毫无疑问,Outlook有一些等效的机制。
之后,你会看到Eudora,Pine,
等的文档。
TJG
在文章< 11 ********************** @ y80g2000hsf.googlegroups .com> ;,, br /> lu********@gmail.com < lu ****** **@gmail.com写的:
>您好,
从用户启动用户标准邮件客户端的最简单方法
Python程序是通过创建mailto:URL并启动
webbrowser:
def mailto_url(to = None,subject = None,body = None,cc = None):
"""
将内容编码为mailto链接,如
http://www.faqs.org/rfcs/rfc2368.html
部分取自
http:// selfht ml.teamone.de/html/verweise/email.htm
"""
url =" mailto:" + urllib.quote(to.strip()," @,")
sep ="?"
if cc:
url + = sep +" cc =" + urllib.quote(cc," @,")
sep ="&"
if subject:
url + = sep +" subject =" + urllib.quote(subject,"")
sep ="&"
if body:
#另请注意邮件正文中的换行必须是用%0D%0A编码的
#。 (RFC 2368)
body =" \\\\ n" .join(body.splitlines())
url + = sep +" body =" + urllib.quote(body,"")
sep ="&"
return url
import webbrowser
url = mailto_url(...)
webbrowser.open(url,new = 1)
(摘自
http://svn.berlios .de / wsvn / lino / trun ... ile& rev = 0& sc = 0 )
但此方法有限:您无法指定要附加的文件
给邮件。我想如果正文文本过于复杂就会出现问题。
有人知道更好的方法吗?
至少在Windows上应该是可行的,因为Acrobat Reader能够做到这一点。
En Fri,2007年5月4日05:07:44 -0300, lu ******** @ gmail.com
< lu ******** @gmail.comescribió:
通过创建mailto:URL并启动
webbrowser:
但是这种方法是有限的:你不能指定要附加的文件
到邮件。我想如果正文文本
太复杂会有问题。
有人知道更好的方法吗?
它应该至少可以在Windows上使用,因为Acrobat Reader能够做到这一点。
在Windows上你可以使用MAPI。
-
Gabriel Genellina >
Hello,
the simplest way to launch the user''s standard mail client from a
Python program is by creating a mailto: URL and launching the
webbrowser:
def mailto_url(to=None,subject=None,body=None,cc=None) :
"""
encodes the content as a mailto link as described on
http://www.faqs.org/rfcs/rfc2368.html
Examples partly taken from
http://selfhtml.teamone.de/html/verweise/email.htm
"""
url = "mailto:" + urllib.quote(to.strip(),"@,")
sep = "?"
if cc:
url+= sep + "cc=" + urllib.quote(cc,"@,")
sep = "&"
if subject:
url+= sep + "subject=" + urllib.quote(subject,"")
sep = "&"
if body:
# Also note that line breaks in the body of a message MUST be
# encoded with "%0D%0A". (RFC 2368)
body="\r\n".join(body.splitlines())
url+= sep + "body=" + urllib.quote(body,"")
sep = "&"
return url
import webbrowser
url = mailto_url(...)
webbrowser.open(url,new=1)
(Excerpt from http://svn.berlios.de/wsvn/lino/trun...ile&rev=0&sc=0)
But this method is limited: you cannot specify a file to be attached
to the mail. And I guess that there would be problems if the body text
is too complex.
Does somebody know about a better method?
It should be possible at least on Windows, since Acrobat Reader is
able to do it.
Thanks in advance for any hints!
Luc Saffre
lu********@gmail.com wrote:the simplest way to launch the user''s standard mail client from a
Python program is by creating a mailto: URL and launching the
webbrowser:[... snip code ...]
But this method is limited: you cannot specify a file to be attached
to the mail. And I guess that there would be problems if the body text
is too complex.
Does somebody know about a better method?
It should be possible at least on Windows, since Acrobat Reader is
able to do it.I''m going to stick my neck out and say: I doubt
if there''s one recognised, approved method. That
would require every email client to have a way
of accepting a command which said "Open up a new
email and put this, this, and this into that field,
that space, and that attachment." The only thing
I can think of which comes close is the mailto:
protocol you refer to, but according to its RFC
http://www.faqs.org/rfcs/rfc2368.html
the only fields allowed are headers and the special
case of "body" which, as you point out, is hardly
intended for embedded attachments.
I would imagine that Acrobat must special case
known email clients and probably won''t work for
some obscure client. Thunderbird, for example,
seems (haven''t tried it) to allow for an attachment:
http://www.mozilla.org/docs/command-line-args.html
Doubtless Outlook has some equivalent mechanism. After
that, you''re down to looking at docs for Eudora, Pine,
etc.
TJG
In article <11**********************@y80g2000hsf.googlegroups .com>,
lu********@gmail.com <lu********@gmail.comwrote:>Hello,
the simplest way to launch the user''s standard mail client from a
Python program is by creating a mailto: URL and launching the
webbrowser:
def mailto_url(to=None,subject=None,body=None,cc=None) :
"""
encodes the content as a mailto link as described on
http://www.faqs.org/rfcs/rfc2368.html
Examples partly taken from
http://selfhtml.teamone.de/html/verweise/email.htm
"""
url = "mailto:" + urllib.quote(to.strip(),"@,")
sep = "?"
if cc:
url+= sep + "cc=" + urllib.quote(cc,"@,")
sep = "&"
if subject:
url+= sep + "subject=" + urllib.quote(subject,"")
sep = "&"
if body:
# Also note that line breaks in the body of a message MUST be
# encoded with "%0D%0A". (RFC 2368)
body="\r\n".join(body.splitlines())
url+= sep + "body=" + urllib.quote(body,"")
sep = "&"
return url
import webbrowser
url = mailto_url(...)
webbrowser.open(url,new=1)
(Excerpt from
http://svn.berlios.de/wsvn/lino/trun...ile&rev=0&sc=0)
But this method is limited: you cannot specify a file to be attached
to the mail. And I guess that there would be problems if the body text
is too complex.
Does somebody know about a better method?
It should be possible at least on Windows, since Acrobat Reader is
able to do it.
En Fri, 04 May 2007 05:07:44 -0300, lu********@gmail.com
<lu********@gmail.comescribió:
the simplest way to launch the user''s standard mail client from a
Python program is by creating a mailto: URL and launching the
webbrowser:
But this method is limited: you cannot specify a file to be attached
to the mail. And I guess that there would be problems if the body text
is too complex.
Does somebody know about a better method?
It should be possible at least on Windows, since Acrobat Reader is
able to do it.On Windows you can use MAPI.
--
Gabriel Genellina
这篇关于调用用户的标准邮件客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!