473,788 Members | 2,784 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

invoke user's standard mail client

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=N one,subject=Non e,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(su bject,"")
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".joi n(body.splitlin es())
url+= sep + "body=" + urllib.quote(bo dy,"")
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

May 4 '07 #1
14 4848
lu********@gmai l.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
May 4 '07 #2
In article <11************ **********@y80g 2000hsf.googleg roups.com>,
lu********@gmai l.com <lu********@gma il.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=N one,subject=Non e,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(su bject,"")
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".joi n(body.splitlin es())
url+= sep + "body=" + urllib.quote(bo dy,"")
sep = "&"
return url

import webbrowser
url = mailto_url(...)
webbrowser.ope n(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.
May 4 '07 #3
En Fri, 04 May 2007 05:07:44 -0300, lu********@gmai l.com
<lu********@gma il.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
May 6 '07 #4
Gabriel Genellina schrieb:
En Fri, 04 May 2007 05:07:44 -0300, lu********@gmai l.com
<lu********@gma il.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.

import win32api
win32api.ShellE xecute(0,'open' ,'mailto:',None ,None,0)
May 6 '07 #5
Stefan Sonnenberg-Carstens schrieb:
Gabriel Genellina schrieb:
>En Fri, 04 May 2007 05:07:44 -0300, lu********@gmai l.com
<lu********@gm ail.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.
import win32api
win32api.ShellE xecute(0,'open' ,'mailto:',None ,None,0)
For completeness

import win32api
win32api.ShellE xecute(0,'open' ,'mailto: gu***@python.or g',None,None,0)

May 6 '07 #6
On May 6, 9:50 am, "Gabriel Genellina" <gagsl-...@yahoo.com.a rwrote:
On Windows you can use MAPI.
But how? I could not find any starting point.

I found examples about sending mail directly, which gives me the
impression that MAPI is just Microsoft's version of SMTP. This is not
what I need. I need the user's client to start, so that the user may
edit the message and decide herself whether she clicks on the Send
button to really send it.

Luc

May 7 '07 #7
On May 6, 10:08 am, Stefan Sonnenberg-Carstens
<stefan.sonnenb ...@pythonmeist er.comwrote:
Stefan Sonnenberg-Carstens schrieb:
Gabriel Genellina schrieb:
En Fri, 04 May 2007 05:07:44 -0300, luc.saf...@gmai l.com
<luc.saf...@gma il.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.
import win32api
win32api.ShellE xecute(0,'open' ,'mailto:',None ,None,0)

For completeness

import win32api
win32api.ShellE xecute(0,'open' ,'mailto: g...@python.org ',None,None,0)
That's equivalent to what the webbrowser module does in my example.
Except that your program won't work on Unix.
Luc

May 7 '07 #8
On May 4, 11:42 am, Tim Golden <m...@timgolden .me.ukwrote:
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."
Tim, I agree, but I hope that we are both wrong.
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.
That's what I plan to do if you are right. At least for Thunderbird
and Outlook...

Luc

May 7 '07 #9
En Mon, 07 May 2007 01:52:18 -0300, lu********@gmai l.com
<lu********@gma il.comescribió:
On May 6, 9:50 am, "Gabriel Genellina" <gagsl-...@yahoo.com.a rwrote:
>On Windows you can use MAPI.
But how? I could not find any starting point.
Get the pywin32 package (Python for Windows extensions) from sourceforge,
install it, and look into the win32comext\map i\demos directory.
I found examples about sending mail directly, which gives me the
impression that MAPI is just Microsoft's version of SMTP. This is not
what I need. I need the user's client to start, so that the user may
edit the message and decide herself whether she clicks on the Send
button to really send it.
No, it should launch the email client (Outlook Express by example) and let
the user confirm it. I think there were some flags to suppress the GUI or
the confirmation, but they're not honored anymore, I presume. At least
Eudora warns the user on such attempts.

--
Gabriel Genellina

May 7 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4107
by: John Altland | last post by:
Here is my basic problem. I have a form that executes a cpu instensive algorithm occupying the first thread. When the algorithm is executed another form pops up telling the user the progress that has been made. Whenever I attempt to update my frmProgress, the events are put placed at the end of the thread's queue and executed after my algorithm is finished. Using the frmProgress.Label.Invoke method with delagates, I have heard would fix...
13
4494
by: Peter Amberg | last post by:
I would like to create a link on my page that opens the standard e-mail application when someone clicks it. It should have at least the subject preset, better if I could preset the body as well. I read somewhere that the TITLE attribute of the A HREF tag can be used to set a subject, so I tried: <A HREF="mailto:" TITLE="MySubject"> This would open the e-mail application, but the TITLE attribute is completely ignored, at least on...
88
12560
by: Mike | last post by:
Is there a way to determine what a user's default email client is? I read a post from 3 years ago that said no. I guess I'm hoping something has come along since then.
21
6591
by: news.btinternnet.com | last post by:
I can do this in IE myLink.click(); //Invoking the handler as if the user had clicked on the link themselves. I need to be able to do the same in Netscape Navigator, can anyone help ?
14
7354
by: stic | last post by:
Hi, I'm in a middle of writing something like 'exception handler wraper' for a set of different methodes. The case is that I have ca. 40 methods form web servicem, with different return values (and types), and with out parmeters. What I want to do is to support each method call with exception (http 404, soap exception, and other types of exceptions) and wrap it with try & catch (a lots of catch ;-)
9
1697
by: John Lafrowda | last post by:
Hello experts, I'm coding a routine which should open a new mail form of the mail standard mail client installed on a system (e.g. outlook, outlook express, netscape mail, etc.) for support reasons. The routine should fill in some textual information. It should, however, not mail the information directly. The user should be able to check the contents of the mail and he should be able to edit the mail before sending it. Consequently, I...
6
3083
by: Wayne Wengert | last post by:
I have a Windows application in which users can select one or more individuals and an email message is created which they then complete and send. I currently use MAPI for this but I want to change the code to invoke whatever email client the users has as the default. Any pointers to some information on how to do this would be appreciated. Wayne
7
5406
by: stephan querengaesser | last post by:
hi ng, i try to invoke a webservice-method with an filter-object, that contains value types. if i don´t want to filter the return value of the method, i have to pass a new instance of the filter-object without setting any properties. but the value type-properties can´t be null and the filter is set to 0 (int) or false (bool). therefore i did implement the propertySpecified-pattern like this:
3
1606
by: Ricardo Vazquez | last post by:
Hi! I have a new problem with this SCENARIO I already described in a previous post: - PBX (a private telephone exchange or switch) - A Telephony Server Application running on computer "A" (it communicates with the PBX via IP) - An ASP.NET application (running on computer "A") for web clients of that telephony server (running on computer "B", "C", etc.)
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10177
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10118
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9969
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5403
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4074
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.