On 07/08/2011 10:16 PM, Tim Roberts wrote:
Steffen Frömer wrote:
i tried to access standard mail application to write a mail.
I know the machanism with urllib, but there is no regular way to add
attachments.
How would you do that with urllib?
I found this on web:

import urllib, webbrowser, win32api

def mailto_url(to=None,subject=None,body=None,cc=None, att=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 = "mail (at) domain.de"
txtSubject = "Test Subject"
body = "Test body"

txtCC = "cc_test (at) com.net"
att = r'C:/Temp/test.txt'


url = mailto_url(txtTo,txtSubject,body,txtCC)
webbrowser.open(url,new=1)

But there are Systems, which don't use MS Outlook.
Is there a way to access the standard mail application.
There is no "standard mail application".  Lots of Windows systems (and
most servers) don't run a mail application at all.  You can try using
MAPI; most of the popular mail apps support that  The COM dispatch is
"Mapi.Session".  There are even some Python samples on using MAPI.
Thanks for this hint. I will try this.

However, to be completely general, you need to use smtplib to send to an
external mail server.
This is no option, because there is noch smtp-server withouf authentication and we need to send mails from different users.

Regards,
Steffen
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to