From iafmgc@unileon.es Wed Sep 19 10:46:57 2001 Received: from isidoro2.unileon.es (isidoro2.unileon.es [193.146.96.2]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f8JAkve22942 for ; Wed, 19 Sep 2001 06:46:57 -0400 (EDT) (envelope-from iafmgc@unileon.es) Received: from intergraph (n104111.unileon.es [193.146.104.111]) by isidoro2.unileon.es (8.9.3/8.9.1) with SMTP id MAA05849 for ; Wed, 19 Sep 2001 12:46:49 +0200 (MET DST) Message-ID: <004001c140f7$cf7dc330$1301a8c0@uimagen> From: =?iso-8859-1?Q?Miguel_Gonz=E1lez?= To: "PostgreSQL PHP" Subject: C function to send an email in PostgreSQL Date: Wed, 19 Sep 2001 12:42:41 +0200 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_003D_01C14108.92B58D00" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 X-Archive-Number: 200109/10 X-Sequence-Number: 531 This is a multi-part message in MIME format. ------=_NextPart_000_003D_01C14108.92B58D00 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Dear all, I want to create a function to send an email. I pass to the function two a= rguments: the email to send, and the text to send. First, I tried with pointers to char. It worked when I just create a function called "sendemail()" with no arguments and set inside the text and the email arguments. When I read some more documentation about how to use strings in PostgreSQL, I discovered that I have to use the text type in my C program I just try it but although it worked before, now I doesnt work. This is what I have tried: #include #include "postgres.h" int sendemail(text *email,text *message) { char string_tosend [300]; sprintf(string_tosend,"echo \"%s\" >/tmp/mailtmp.txt \n",VARDATA(message)); system(string_tosend); sprintf(string_tosend,"mail -s \"message from PostgreSQL\" %s
De= ar=20 all,
 
&n= bsp;I want to=20 create a function to send an email. I pass to the function two arguments: t= he=20 email to send, and the text
to send.

 First, I tried with=20 pointers to char. It worked when I just create a
function called=20 "sendemail()" with no arguments and set inside the text and
the email=20 arguments.

 When I read some more documentation about how to us= e=20 strings in PostgreSQL,
I discovered that I have to use the text type in = my C=20 program I just try it
but
although it worked before, now I doesnt=20 work.

 This is what I have tried:


 #include=20 <stdio.h>
 #include "postgres.h"

 int sendemail(t= ext=20 *email,text *message)
 {

     char=20 string_tosend [300];

     sprintf(string_tosend,= "echo=20 \"%s\"=20 >/tmp/mailtmp.txt
\n",VARDATA(message));

   &nb= sp;=20 system(string_tosend);

    sprintf(string_tosend,"mai= l -s=20 \"message from PostgreSQL\" %s
</tmp/mailtmp.txt=20 \n",VARDATA(message));

    =20 system(string_tosend);

     system("rm=20 /tmp/mailtmp.txt");

     return=20 0;


 }


 and then in the back-end of PostgreS= QL=20 and I declared

 CREATE FUNCTION=20 sendemail(text,text)
 RETURNS int4
 AS=20 '/home/postgres/libpginvuimail.so'
 LANGUAGE 'c';

 and = then=20 SELECT sendemail('postgres','test from backend');

 and it didnt= =20 work. What am I doing wrong?

 I have being testing and I guess = is=20 something to do with the text data type
and how to use it within a C=20 program.

 Many thanks in=20 advance

 Miguel

------=_NextPart_000_003D_01C14108.92B58D00-- From vev@michvhf.com Wed Sep 19 11:32:23 2001 Received: from paprika.michvhf.com (adsl-pool25-183.detroit.mi.ameritech.net [64.108.58.183]) by postgresql.org (8.11.3/8.11.4) with SMTP id f8JBWNe44074 for ; Wed, 19 Sep 2001 07:32:23 -0400 (EDT) (envelope-from vev@michvhf.com) Received: (qmail 94568 invoked by uid 1001); 19 Sep 2001 11:32:21 -0000 Date: Wed, 19 Sep 2001 07:32:21 -0400 (EDT) From: Vince Vielhaber To: =?iso-8859-1?Q?Miguel_Gonz=E1lez?= cc: PostgreSQL PHP Subject: Re: C function to send an email in PostgreSQL In-Reply-To: <004001c140f7$cf7dc330$1301a8c0@uimagen> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from QUOTED-PRINTABLE to 8bit by postgresql.org id f8JBWNe44078 X-Archive-Number: 200109/11 X-Sequence-Number: 532 On Wed, 19 Sep 2001, [iso-8859-1] Miguel González wrote: > Dear all, > > I want to create a function to send an email. I pass to the function two arguments: the email to send, and the text > to send. Have you seen pgMail? http://sourceforge.net/projects/pgmail/ Vince. -- ========================================================================== Vince Vielhaber -- KA8CSH email: vev@michvhf.com http://www.pop4.net 56K Nationwide Dialup from $16.00/mo at Pop4 Networking Online Campground Directory http://www.camping-usa.com Online Giftshop Superstore http://www.cloudninegifts.com ==========================================================================