Received: from resy5.fzk.de (resy5.fzk.de [141.52.68.8]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f8JCgVe75413 for ; Wed, 19 Sep 2001 08:42:31 -0400 (EDT) (envelope-from ch@rodos.fzk.de) Received: by rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id OAA24695; Wed, 19 Sep 2001 14:42:25 +0200 (METDST) From: Haller Christoph Message-Id: <200109191241.OAA23930@rodos> Subject: Re: Registring a C function in PostgreSQL II To: iafmgc@unileon.es (=?iso-8859-1?Q?Miguel_Gonz=E1lez?=) Date: Wed, 19 Sep 2001 14:41:36 METDST Cc: pgsql-sql@postgresql.org In-Reply-To: <002701c140f7$9d75d710$1301a8c0@uimagen>; from "=?iso-8859-1?Q?Miguel_Gonz=E1lez?=" at Sep 19, 101 1:56 pm X-Mailer: Elm [revision: 212.4] X-Archive-Number: 200109/149 X-Sequence-Number: 4827 I'm working on a HP-UX system, so some of the following has to be adapted, but in principle it's the same on every system and it works. First piece of code is a standalone program, which you should always write and test before you start creating C functions inside PostgreSQL. Second piece is your sendemail function slightly modified to make it run on my system. When I do a select sendemail('ch', 'was soll das?') ; I'm receiving an email from postgres. Regards, Christoph First piece: /* cc -Aa -g -I/opt/pgsql/include/ -c sendemtest.c cc sendemail.o sendemtest.o -o sendemtest */ #include #include #include #include "postgres.h" void main() { char buf[1024]; int ln; text *res; text *to; int sendemail(text *email,text *message); strcpy(buf, "Kissenminister Aussinger \n"); ln = strlen(buf); res = (text *) malloc(VARHDRSZ + ln); memset(res, 0, VARHDRSZ + ln); res->vl_len = VARHDRSZ + ln; memcpy(res->vl_dat, buf, (int) ln); strcpy(buf, "ch"); ln = strlen(buf); to = (text *) malloc(VARHDRSZ + ln); memset(to, 0, VARHDRSZ + ln); to->vl_len = VARHDRSZ + ln; memcpy(to->vl_dat, buf, (int) ln); sendemail(to, res); } Second piece: /* cc -Aa -g -I/opt/pgsql/include/ +z -c sendemail.c ld -b -o sendemail.sl sendemail.o CREATE FUNCTION sendemail(text,text) RETURNS int4 AS '/fdsk2/users/ch/tools/pgsql.mydoc/sendemail.sl' LANGUAGE 'c'; DROP FUNCTION sendemail(text,text); */ #include #include #include "postgres.h" int sendemail(text *email,text *message) { int result = 0 ; char string_tosend [300]; sprintf(string_tosend,"/usr/bin/echo \"%s\" >/tmp/mailtmp.txt\n",VARDATA(message)); result += system(string_tosend); sprintf(string_tosend,"/usr/bin/mail -dt %s