X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 9B367D1D885 for ; Fri, 16 Jan 2004 09:01:44 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 76629-10 for ; Fri, 16 Jan 2004 05:01:15 -0400 (AST) Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by svr1.postgresql.org (Postfix) with SMTP id 21063D1B4AE for ; Fri, 16 Jan 2004 05:01:12 -0400 (AST) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Fri Jan 16 10:01:09 2004 +0100 Received: œby rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id KAA18407; Fri, 16 Jan 2004 10:01:09 +0100 (MET) From: Christoph Haller Message-Id: <200401160901.KAA09998@rodos> Subject: Re: Email function using c instead of tclu To: uzo@beya-records.com (beyaRecords - The home Urban music) Date: Fri, 16 Jan 2004 10:01:08 MET Cc: pgsql-sql@postgresql.org In-Reply-To: <7F9A1916-45D3-11D8-8407-0003938366A4@beya-records.com>; from "beyaRecords - The home Urban music" at Jan 13, 104 3:21 pm X-Mailer: Elm [revision: 212.4] X-Virus-Scanned: by amavisd-new at postgresql.org X-Amavis-Alert: BAD HEADER Non-encoded 8-bit data (char 9C hex) in message header 'Received' Received: \234by rodos.fzk.de... ^ X-Archive-Number: 200401/135 X-Sequence-Number: 16528 > > Hi, > I have tried without any success to get this pgmail for tclu resolved. > Does anyone have or know of the same sort of function as pgmail but > supporting c, as this is one of the installed languages I have access > to under postgresql. So for instance: > > CREATE FUNCTION sendemail(x,x) > .... > LANGUAGE 'c'; > > regards > > > Uzo > > Pretty late and pretty old stuff of mine (Sep 19 2001) but it should still work or at least give you some hint. Regards, Christoph 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