pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Miguel González <iafmgc@unileon.es>
To: PostgreSQL PHP <pgsql-php@postgresql.org>
Subject: C function to send an email in PostgreSQL
Date: Wed, 19 Sep 2001 12:42:41 +0200
Message-ID: <004001c140f7$cf7dc330$1301a8c0@uimagen> (raw)

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.

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

     system(string_tosend);

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

     return 0;


 }


 and then in the back-end of PostgreSQL and I declared

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

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

 and it didnt work. What am I doing wrong?

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

 Many thanks in advance

 Miguel

view thread (2+ messages)  latest in thread

Message-ID: <004001c140f7$cf7dc330$1301a8c0@uimagen>
Permalink:  ../004001c140f7$cf7dc330$1301a8c0@uimagen/
Also on:    postgresql.org/message-id/004001c140f7$cf7dc330$1301a8c0@uimagen

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: iafmgc@unileon.es
  Subject: Re: C function to send an email in PostgreSQL
  In-Reply-To: <004001c140f7$cf7dc330$1301a8c0@uimagen>
  References: <004001c140f7$cf7dc330$1301a8c0@uimagen>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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