pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Email function using c instead of tclu
2+ messages / 2 participants
[nested] [flat]

* Email function using c instead of tclu
@ 2004-01-13 14:19 beyaRecords - The home Urban music <uzo@beya-records.com>
  2004-01-16 10:01 ` Re: Email function using c instead of tclu Christoph Haller <ch@rodos.fzk.de>
  0 siblings, 1 reply; 2+ messages in thread

From: beyaRecords - The home Urban music @ 2004-01-13 14:19 UTC (permalink / raw)
  To: pgsql-sql

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




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Email function using c instead of tclu
  2004-01-13 14:19 Email function using c instead of tclu beyaRecords - The home Urban music <uzo@beya-records.com>
@ 2004-01-16 10:01 ` Christoph Haller <ch@rodos.fzk.de>
  0 siblings, 0 replies; 2+ messages in thread

From: Christoph Haller @ 2004-01-16 10:01 UTC (permalink / raw)
  To: uzo@beya-records.com; +Cc: pgsql-sql

> 
> 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#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 <stdio.h>
 #include <stdlib.h>
 #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 </tmp/mailtmp.txt \n",
	     VARDATA(email));

     result += system(string_tosend);

     result += system("/usr/bin/rm /tmp/mailtmp.txt");

     return result;


 }




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2004-01-16 10:01 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-01-13 14:19 Email function using c instead of tclu beyaRecords - The home Urban music <uzo@beya-records.com>
2004-01-16 10:01 ` Christoph Haller <ch@rodos.fzk.de>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox