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 14 4790 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
Gabriel Genellina schrieb:
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.
import win32api
win32api.ShellExecute(0,'open','mailto:',None,None ,0)
Stefan Sonnenberg-Carstens schrieb:
Gabriel Genellina schrieb:
>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.
import win32api
win32api.ShellExecute(0,'open','mailto:',None,None ,0)
For completeness
import win32api
win32api.ShellExecute(0,'open','mailto: gu***@python.org',None,None,0)
On May 6, 9:50 am, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
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
On May 6, 10:08 am, Stefan Sonnenberg-Carstens
<stefan.sonnenb...@pythonmeister.comwrote:
Stefan Sonnenberg-Carstens schrieb:
Gabriel Genellina schrieb:
En Fri, 04 May 2007 05:07:44 -0300, luc.saf...@gmail.com
<luc.saf...@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.
import win32api
win32api.ShellExecute(0,'open','mailto:',None,None ,0)
For completeness
import win32api
win32api.ShellExecute(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
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
En Mon, 07 May 2007 01:52:18 -0300, lu********@gmail.com
<lu********@gmail.comescribió:
On May 6, 9:50 am, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
>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\mapi\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
On 4 Mai, 18:54, cla...@lairds.us (Cameron Laird) wrote:
.
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.
Portland [1] provides scripts (xdg-open, xdg-email...) which overlap
with the functionality provided by the desktop module: http://www.python.org/pypi/desktop
The desktop module should even work with Windows as well, but it seems
that xdg-email has the edge in terms of providing the inquirer's
desired support for composing e-mail messages (on Free Software
desktops, anyway).
Paul
[1] http://portland.freedesktop.org/wiki/
In article <u2************@lairds.us>, Cameron Laird <cl****@lairds.uswrote:
>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.
. . . Portland <URL: http://ct.enews.eweek.com/rd/cts?d=1...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/developerwork...-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
On May 7, 10:28 am, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
>
Get the pywin32 package (Python for Windows extensions) from sourceforge,
install it, and look into the win32comext\mapi\demos directory.
Thanks for the hint, Gabriel.
Wow, that's heavily spiced code! When I invoke mapisend.py I get:
Traceback (most recent call last):
File "mapisend1.py", line 85, in <module>
SendEMAPIMail(SendSubject, SendMessage, SendTo,
MAPIProfile=MAPIProfile)
File "mapisend1.py", line 23, in SendEMAPIMail
mapi.MAPIInitialize(None)
pywintypes.com_error: (-2147467259, 'Unspecified error', None, None)
But what is a MAPI profile? I left this variable blank. Do I need MS
Exchange Server to run this demo?
En Mon, 07 May 2007 18:00:06 -0300, lu********@gmail.com
<lu********@gmail.comescribió:
On May 7, 10:28 am, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
>> Get the pywin32 package (Python for Windows extensions) from sourceforge, install it, and look into the win32comext\mapi\demos directory.
Thanks for the hint, Gabriel.
Wow, that's heavily spiced code! When I invoke mapisend.py I get:
Traceback (most recent call last):
File "mapisend1.py", line 85, in <module>
SendEMAPIMail(SendSubject, SendMessage, SendTo,
MAPIProfile=MAPIProfile)
File "mapisend1.py", line 23, in SendEMAPIMail
mapi.MAPIInitialize(None)
pywintypes.com_error: (-2147467259, 'Unspecified error', None, None)
But what is a MAPI profile? I left this variable blank.
You can register several profiles (or users, or accounts); leave it blank
to use the default profile.
Do I need MS
Exchange Server to run this demo?
No. But this simple example used to work fine for me, but not anymore :( .
Perhaps it has to do with my Eudora configuration. I've never used Outlook
nor OutlookExpress btw.
You may find this thread interesting: http://mail.python.org/pipermail/pyt...er/003985.html
--
Gabriel Genellina
On May 7, 2:00 pm, "luc.saf...@gmail.com" <luc.saf...@gmail.com>
wrote:
On May 7, 10:28 am, "Gabriel Genellina" <gagsl-...@yahoo.com.ar>
wrote:
Get the pywin32 package (Python for Windows extensions) from sourceforge,
install it, and look into the win32comext\mapi\demos directory.
Thanks for the hint, Gabriel.
Wow, that's heavily spiced code! When I invoke mapisend.py I get:
Traceback (most recent call last):
File "mapisend1.py", line 85, in <module>
SendEMAPIMail(SendSubject, SendMessage, SendTo,
MAPIProfile=MAPIProfile)
File "mapisend1.py", line 23, in SendEMAPIMail
mapi.MAPIInitialize(None)
pywintypes.com_error: (-2147467259, 'Unspecified error', None, None)
But what is a MAPI profile?
It's an abstraction of incoming and outgoing mail accounts. In UNIX
terms it's kind of like running local sendmail that forwards mail to
another server and fetchmail that fetches mail from external inboxes,
e.g. it's a proxy between you and outgoing/incoming mail server.
I left this variable blank. Do I need MS
Exchange Server to run this demo?
No, but you need an account on some mail server and some email program
should create a MAPI profile to represent that account on your local
computer. As I understand creation of MAPI profiles is not a common
practice among non-Microsoft products, for example my computer with
Lotus Notes doesn't have any MAPI profiles.
-- Leo This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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.
|
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 ?
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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...
|
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...
| |