invoke user's standard mail client

Cameron Laird claird at lairds.us
Mon May 7 06:26:53 EDT 2007


In article <u25sg4-irp.ln1 at lairds.us>, Cameron Laird <claird at lairds.us> wrote:
>In article <1178266064.922925.125760 at y80g2000hsf.googlegroups.com>,
>luc.saffre at gmail.com <luc.saffre at gmail.com> wrote:
>>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/trunk/src/lino/tools/mail.py?op=file&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.
>			.
>			.
>			.
>Portland <URL:
>http://ct.enews.eweek.com/rd/cts?d=186-6281-53-799-798304-697089-0-0-0-1 >
>is the best standardization of this problem we have under Linux.
>
>I'll address Windows in a subsequent follow-up.

A.  Apologies!  I'm sorry about the URL above; it was
    completely wrong.  I intended <URL:
    http://www-128.ibm.com/developerworks/linux/library/l-portland.html >.
B.  The best approach I know under Windows is to invoke
            start mailto:$ADDRESS
    1.  That invocation does *not* communicate
	subject, attachments, ...  To do so 
	adequately involves application-specific
	work, as other follow-ups have mentioned.
    2.  "start" has its own complexities.  The
	best invocation from console-based Python
	is likely to be 
	    start /w "" mailto:$ADDRESS



More information about the Python-list mailing list