[Tutor] Send attachment

Jorge Louis De Castro jorge at bcs.org.uk
Mon Aug 1 13:17:12 CEST 2005

Thanks for the reply

I did try your approach at first but then, Martin Walsh on this mailing list hinted at something way simpler and elegant, a solution that actually adjusts itself to the default mail client of the user.

It consists of creating an .eml file with all the blurb that goes with it (save an email message as a draft and open it to see what needs to go there).

Then it is a simple matter of calling os.startfile(<filename>) and the OS will open the file with whatever program is associated with those extensions, typically the default mail client.

> import os
> os.startfile('foo.eml')

I think it's neat, it does what I want in an elegant way, and it keeps me from mixing languages and all that jazz.


  ----- Original Message ----- 
  From: Liam Clarke 
  To: Jorge Louis De Castro 
  Cc: tutor at python.org 
  Sent: Friday, July 22, 2005 12:45 AM
  Subject: Re: [Tutor] Send attachment

  If it's Outlook, you can use the win32python library to control it via ActiveX/COM+


  Here's an example using VB to control Outlook - 

  The language differs, but the basic principle remains the same. 

  Create an Application.Outlook object, and then use it's methods. 

  I know there's a way to use the default mail client 
  ( as in Excel VBA's - application.showdialog(xlDialogs.SendMail) ) but blowed if I can figure it out. The above VBA bit automatically attaches the open spreadsheet, so unsure if you can hijack it. 

  Good luck, and if you google how to use the default email client, let me know!

  Liam Clarke

  On 7/22/05, Jorge Louis De Castro <jorge at bcs.org.uk> wrote:

    Any ideas how I can use Python and the Windows API to open a PC's mail client and send an attachment?
    The idea is saving some data onto a file and then invoke the email client (OE or Outlook or whatever is the default on the machine) with the recipient's address filled in and the file ready to be sent as an attachment. 
    Kinda like when we right-click on a file and select the "send to mail recipient" behavior.
    Been reading docs, trying out samples, and googling this for a few days to no avail.


    Tutor maillist  -  Tutor at python.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050801/734bea4e/attachment.htm

More information about the Tutor mailing list