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--