Re: how to make desktop app send email?



On Thu, 2004-07-15 at 12:58 -0500, Linas Vepstas wrote:

> I have a desktop app ("gnomtime", actually, gttr.sourceforge.net) with 
> several free-text areas in it.  It like to be able to add a menu item
> that says "email this".  Clicking on the menu would start the user's
> favorite email client, push the text into it, and let them complete
> the addressing from there, etc.
> 
> What's the best way of doing this?

Evolution provides two things for this:

- evolution mailto:foo bar com?subject=Hello World&body=Good bye&

- a CORBA interface for the composer

The first one has the quoting problems you would expect, but it's really
simple.  If your text areas are to be sent as attachments rather than
the message body, you may be able to do something really easy:

	evolution mailto:foo bar com?attach=file:///foo/blah.txt

This will bring up a composer window with only the To: field filled in,
plus an attachment.

The CORBA interface is nicer.  The repository ID is 

	OAFIID:GNOME_Evolution_Mail_Composer:1.5

for Evolution 1.5.  Look at Evolution-Composer.idl for the actual
interface.  For a really short/untested summary:

#include <libbonobo.h>
#include <Evolution-Composer.h>

static gboolean
mail (const char *recipient, const char *subject, const char *body)
{
  GNOME_Evolution_Composer composer;
  CORBA_Environment ev;
  GNOME_Evolution_Recipient recipient;
  GNOME_Evolution_RecipientList rl;

  CORBA_exception_init (&ev);
  composer = bonobo_get_object ("OAFIID:GNOME_Evolution_Mail_Composer:1.5",
                                "IDL:GNOME/Evolution:Composer:1.5",
				&ev);
  if (composer == CORBA_OBJECT_NIL) {
    CORBA_exception_free (&ev);
    return FALSE;
  }

  recipient.name = "";
  recipient.address = recipient;
  rl._length = 1;
  rl._buffer = &recipient;

  CORBA_exception_init (&ev);
  GNOME_Evolution_Composer_setHeaders (composer, 
                                       "sender you com",
                                       &rl,
                                       NULL,
                                       NULL,
                                       subject,
                                       &ev);
  if (ev._major != CORBA_NO_EXCEPTION) {
    CORBA_exception_free (&ev);
    return FALSE;
  }

  CORBA_exception_init (&ev);
  GNOME_Evolution_Composer_setBody (composer, body, "text/plain", &ev);
  if (ev._major != CORBA_NO_EXCEPTION) {
    CORBA_exception_free (&ev);
    return FALSE;
  }

  CORBA_exception_init (&ev);
  GNOME_Evolution_Composer_show (composer, &ev);
  if (ev._major != CORBA_NO_EXCEPTION) {
    CORBA_exception_free (&ev);
    return FALSE;
  }

  CORBA_exception_init (&ev);
  bonobo_object_release_unref (composer, &ev);
  if (ev._major != CORBA_NO_EXCEPTION) {
    CORBA_exception_free (&ev);
    return FALSE;
  }

  return TRUE;
}

  Federico




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]