FAQ
Hi,
I'm trying to launch standard mail app in windows and after looking
around most look like this:

import urllib, webbrowser, win32api
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
"""
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

url = mailto_url(txtTo,txtSubject,body,txtCC)
# win32api.ShellExecute(0,'open',url,None,None,0)
webbrowser.open(url,new=1)
# os.startfile(url)

all of these are having "WindowsError : [Error 5] Access is denied"
errors. I'm using windows xp and python 2.5. I have outlook 2007
installed as a default mail client. Clicking on any mailto links in html
brings up the normal write mail from the mail client. Any ideas why this
is happening or how do I debug what access is being denied?
Thanks for any help
Astan

Search Discussions

  • Astan Chee at Dec 18, 2009 at 5:56 pm
    Hi,
    I don't know if my last mail made it or not but here it is again.
    I'm trying to launch standard mail app in windows and after looking
    around most look like this:

    import urllib, webbrowser, win32api
    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
    """
    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

    url = mailto_url(txtTo,txtSubject,body,txtCC)
    # win32api.ShellExecute(0,'open',url,None,None,0)
    webbrowser.open(url,new=1)
    # os.startfile(url)

    all of these are having "WindowsError : [Error 5] Access is denied"
    errors. I'm using windows xp and python 2.5. I have outlook 2007
    installed as a default mail client. Clicking on any mailto links in html
    brings up the normal write mail from the mail client. Any ideas why this
    is happening or how do I debug what access is being denied?
    Thanks for any help
    Astan
  • Kev Dwyer at Dec 18, 2009 at 7:18 pm

    On Sat, 19 Dec 2009 04:56:34 +1100, Astan Chee wrote:

    Hi,
    I don't know if my last mail made it or not but here it is again. I'm
    trying to launch standard mail app in windows and after looking around
    most look like this:

    import urllib, webbrowser, win32api
    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 """
    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

    url = mailto_url(txtTo,txtSubject,body,txtCC) #
    win32api.ShellExecute(0,'open',url,None,None,0)
    webbrowser.open(url,new=1)
    # os.startfile(url)

    all of these are having "WindowsError : [Error 5] Access is denied"
    errors. I'm using windows xp and python 2.5. I have outlook 2007
    installed as a default mail client. Clicking on any mailto links in html
    brings up the normal write mail from the mail client. Any ideas why this
    is happening or how do I debug what access is being denied? Thanks for
    any help
    Astan
    Hello Astan,

    Your code executes without error for me on Win98 (!) with Python 2.5 or
    XP with Python 2.6.

    It would help people to help you if you could provide the *exact* console
    output from when you try to execute the code, *including* the traceback.
    That way we can work out which line of code is hitting the exception.

    Cheers,

    Kev
  • Astan Chee at Dec 18, 2009 at 7:36 pm

    Kev Dwyer wrote:
    Hello Astan,

    Your code executes without error for me on Win98 (!) with Python 2.5 or
    XP with Python 2.6.

    It would help people to help you if you could provide the *exact* console
    output from when you try to execute the code, *including* the traceback.
    That way we can work out which line of code is hitting the exception.

    Cheers,

    Kev
    Hi,
    My mistake. The length of body is over 1400 characters. Here is my
    updated code and result:

    import urllib, webbrowser, win32api
    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 """
    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

    txtTo = "test at com.com"
    txtSubject = "Test Subject"
    body = "Test body"
    for t in range(278):
    body+="test "
    txtCC = "cc_test at com.com"

    url = mailto_url(txtTo,txtSubject,body,txtCC)
    #win32api.ShellExecute(0,'open',url,None,None,0)
    webbrowser.open(url,new=1)
    # os.startfile(url)

    result:

    Traceback (most recent call last):
    File "C:/stanc_home/python/mail_test.py", line 32, in <module>
    webbrowser.open(url,new=1)
    File "C:\Python25\lib\webbrowser.py", line 61, in open
    if browser.open(url, new, autoraise):
    File "C:\Python25\lib\webbrowser.py", line 518, in open
    os.startfile(url)
    WindowsError: [Error 5] Access is denied: 'mailto:
    test at com.com?cc=cc_test at com.com&subject=Test%20Subject&body=Test%20bodytest%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%20'

    Is there some sort of limitation here? If I shorten the string, it works
    fine. You're right, but I'm wondering if there is a way to go around
    this limitation.
    Thanks again
    Cheers
    Astan
  • Kev Dwyer at Dec 18, 2009 at 8:24 pm

    On Sat, 19 Dec 2009 06:36:32 +1100, Astan Chee wrote:

    Kev Dwyer wrote:
    Hello Astan,

    Your code executes without error for me on Win98 (!) with Python 2.5 or
    XP with Python 2.6.

    It would help people to help you if you could provide the *exact*
    console output from when you try to execute the code, *including* the
    traceback. That way we can work out which line of code is hitting the
    exception.

    Cheers,

    Kev
    Hi,
    My mistake. The length of body is over 1400 characters. Here is my
    updated code and result:

    import urllib, webbrowser, win32api
    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 """ 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

    txtTo = "test at com.com"
    txtSubject = "Test Subject"
    body = "Test body"
    for t in range(278):
    body+="test "
    txtCC = "cc_test at com.com"

    url = mailto_url(txtTo,txtSubject,body,txtCC)
    #win32api.ShellExecute(0,'open',url,None,None,0)
    webbrowser.open(url,new=1)
    # os.startfile(url)

    result:

    Traceback (most recent call last):
    File "C:/stanc_home/python/mail_test.py", line 32, in <module>
    webbrowser.open(url,new=1)
    File "C:\Python25\lib\webbrowser.py", line 61, in open
    if browser.open(url, new, autoraise):
    File "C:\Python25\lib\webbrowser.py", line 518, in open
    os.startfile(url)
    WindowsError: [Error 5] Access is denied: 'mailto:
    test at com.com?cc=cc_test at com.com&subject=Test%20Subject&body=Test%
    20bodytest%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20t
    est%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20test%20test%20test%20te
    st%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20tes
    t%20test%20test%20test%20test%20test%20test%20test%20test%20test%20test
    %20test%20test%20test%20test%20test%20test%20test%20test%20test%20test%
    20test%20test%20test%20test%20test%20test%20test
    %20test%20test%20test%20test%20test%20'

    Is there some sort of limitation here? If I shorten the string, it works
    fine. You're right, but I'm wondering if there is a way to go around
    this limitation.
    Thanks again
    Cheers
    Astan
    Hmmm.

    For me, body < 1400 opens an outlook message form, body > 1400 opens IE7.

    No time to look into this right now, but perhaps this is a windows thing.

    Don't know why you get windowserror, perhaps permissions???

    I'll try and look again later/tomorrow.

    Cheers,

    Kev
  • Kev Dwyer at Dec 19, 2009 at 12:19 pm

    On Sat, 19 Dec 2009 06:36:32 +1100, Astan Chee wrote:

    Kev Dwyer wrote:
    Hello Astan,

    Your code executes without error for me on Win98 (!) with Python 2.5 or
    XP with Python 2.6.

    It would help people to help you if you could provide the *exact*
    console output from when you try to execute the code, *including* the
    traceback. That way we can work out which line of code is hitting the
    exception.

    Cheers,

    Kev
    Hi,
    My mistake. The length of body is over 1400 characters. Here is my
    updated code and result:

    import urllib, webbrowser, win32api
    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 """ 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

    txtTo = "test at com.com"
    txtSubject = "Test Subject"
    body = "Test body"
    for t in range(278):
    body+="test "
    txtCC = "cc_test at com.com"

    url = mailto_url(txtTo,txtSubject,body,txtCC)
    #win32api.ShellExecute(0,'open',url,None,None,0)
    webbrowser.open(url,new=1)
    # os.startfile(url)

    result:

    Traceback (most recent call last):
    File "C:/stanc_home/python/mail_test.py", line 32, in <module>
    webbrowser.open(url,new=1)
    File "C:\Python25\lib\webbrowser.py", line 61, in open
    if browser.open(url, new, autoraise):
    File "C:\Python25\lib\webbrowser.py", line 518, in open
    os.startfile(url)
    WindowsError: [Error 5] Access is denied: 'mailto:
    test at com.com?cc=cc_test at com.com&subject=Test%20Subject&body=Test% <snip>
    Is there some sort of limitation here? If I shorten the string, it works
    fine. You're right, but I'm wondering if there is a way to go around
    this limitation.
    Thanks again
    Cheers
    Astan

    Hello Astan,

    After a bit of experimentation I find I get the same problem on XP using
    2.6 for len(body) > 1973, using the os.startfile method. Some light
    googling suggests this is probably a limit within Outlook itself.

    If you just want a way to start Outlook programmatically you may be able
    to work around this by automating Outlook - try googling python outlook
    automation.

    If you want to start a default mail client on any machine using the
    mailto protocol then you'll have to limit the size of your message
    bodies. You may find that other mail clients have limits too - I doubt
    that any client (or browser) will accept urls of unlimited size.

    Cheers,

    Kev

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedDec 18, '09 at 3:31p
activeDec 19, '09 at 12:19p
posts6
users2
websitepython.org

2 users in discussion

Astan Chee: 3 posts Kev Dwyer: 3 posts

People

Translate

site design / logo © 2022 Grokbase