C function to send an email in PostgreSQL

From: Miguel González <iafmgc(at)unileon(dot)es>
To: "PostgreSQL PHP" <pgsql-php(at)postgresql(dot)org>
Subject: C function to send an email in PostgreSQL
Date: 2001-09-19 10:42:41
Message-ID: 004001c140f7$cf7dc330$1301a8c0@uimagen
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

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

Responses

Browse pgsql-php by date

  From Date Subject
Next Message Vince Vielhaber 2001-09-19 11:32:21 Re: C function to send an email in PostgreSQL
Previous Message Peter 2001-09-19 00:50:33 PHP session issue